Keeta LogoKeeta Logo@keetanetwork/keetanet-client
    Preparing search index...

    A P2PSwitch is a method of coordinating messages from peers (either connected or known) with a Node.

    Index

    Constructors

    Properties

    config: Omit<Required<P2PConfig>, "kv"> & { kv: KVStorageProviderAPI }
    isInstance: (obj: any, strict?: boolean) => obj is P2PSwitch = ...

    Methods

    • Add a manual peer to initiate peering process

      The switch will periodically reach out to this peer to build its peer database

      Parameters

      • peer: P2PPeer
      • schedule: boolean = true

      Returns void

    • Parameters

      • connString: string

      Returns Promise<undefined | P2PConnection>

    • Receive a message from a connection

      This message will get sent to our local node, which may then rebroadcast it

      Parameters

      Returns Promise<boolean>

    • Our own peer information

      Returns Promise<null | P2PPeer>

    • Send a message to one or more peers

      If they are already connected that connection will be re-used, otherwise a new connection will be established.

      If "to" is null then it will be sent to a sampling of peers

      Parameters

      • to:
            | null
            | Account<ECDSA_SECP256K1 | ED25519 | ECDSA_SECP256R1>
            | P2PPeer
            | P2PConnection

        Where to send the message

      • id: string

        Unique message identifier

      • type: string

        Message type

      • data: any

        Message data, must be serializable to JSON

      • Optionalttl: number

        Maximum number of hops to pass through

      • Optionalexclude: (string | P2PConnection)[]

        List of connections to exclude (e.g., because we got the message from that connection) if "to" is null

      • skipConnectToPeers: boolean = false

        Skip creating new connections to send to, only connected clients will be sent the message

      Returns Promise<boolean>

      If the message could be delivered to at least one peer

    • Stop this switch

      Returns Promise<void>

    • Handle any waiting that needs to be done

      Returns Promise<void>

    • Parameters

      • messageBuffer: ArrayBuffer | Buffer

      Returns JSONMessage | { reason: string; valid: false }