libp2p/switch

    Dark Mode
Search:
Group by:
  Source   Edit

The switch is the core of libp2p, which brings together the transports, the connection manager, the upgrader and other parts to allow programs to use libp2p

Types

Switch {.public.} = ref object of Dial
  peerInfo*: PeerInfo
  connManager*: ConnManager
  transports*: seq[Transport]
  ms*: MultistreamSelect
  acceptFuts: seq[Future[void]]
  dialer*: Dial
  peerStore*: PeerStore
  nameResolver*: NameResolver
  started: bool
  Source   Edit

Procs

proc addConnEventHandler(s: Switch; handler: ConnEventHandler;
                         kind: ConnEventKind) {.public, ...raises: [],
    tags: [RootEffect].}

Adds a ConnEventHandler, which will be triggered when a connection to a peer is created or dropped. There may be multiple connections per peer.

The handler should not raise.

  Source   Edit
proc addPeerEventHandler(s: Switch; handler: PeerEventHandler;
                         kind: PeerEventKind) {.public, ...raises: [],
    tags: [RootEffect].}

Adds a PeerEventHandler, which will be triggered when a peer connects or disconnects from us.

The handler should not raise.

  Source   Edit
proc dial(s: Switch; peerId: PeerId; addrs: seq[MultiAddress]; proto: string): Future[
    Connection] {.public, ...raises: [], tags: [RootEffect].}
Connected to a peer and open a stream with the specified proto   Source   Edit
proc dial(s: Switch; peerId: PeerId; proto: string): Future[Connection] {.
    public, ...raises: [], tags: [RootEffect].}
Open a stream to a connected peer with the specified proto   Source   Edit
proc disconnect(s: Switch; peerId: PeerId): Future[void] {....gcsafe, public,
    ...raises: [], tags: [RootEffect].}
Disconnect from a peer, waiting for the connection(s) to be dropped   Source   Edit
proc isConnected(s: Switch; peerId: PeerId): bool {.public, ...raises: [], tags: [].}
returns true if the peer has one or more associated connections   Source   Edit
proc mount[T: LPProtocol](s: Switch; proto: T; matcher: Matcher = nil) {....gcsafe,
    raises: [Defect, LPError], public, ...raises: [].}
mount a protocol to the switch   Source   Edit
proc newSwitch(peerInfo: PeerInfo; transports: seq[Transport];
               identity: Identify; secureManagers: openArray[Secure] = [];
               connManager: ConnManager; ms: MultistreamSelect;
               nameResolver: NameResolver = nil; peerStore = PeerStore.new()): Switch {.
    ...raises: [Defect, LPError], public, ...raises: [], tags: [RootEffect].}
  Source   Edit
proc removeConnEventHandler(s: Switch; handler: ConnEventHandler;
                            kind: ConnEventKind) {.public, ...raises: [],
    tags: [RootEffect].}
  Source   Edit
proc removePeerEventHandler(s: Switch; handler: PeerEventHandler;
                            kind: PeerEventKind) {.public, ...raises: [],
    tags: [RootEffect].}
  Source   Edit
proc start(s: Switch): Future[void] {....gcsafe, public(), stackTrace: false,
                                      ...gcsafe, raises: [], raises: [],
                                      tags: [RootEffect].}
Start listening on every transport   Source   Edit

Methods

method addTransport(s: Switch; t: Transport) {....raises: [], tags: [].}
  Source   Edit
method connect(s: Switch; peerId: PeerId; addrs: seq[MultiAddress];
               forceDial = false): Future[void] {.public, ...raises: [],
    tags: [RootEffect].}
Connects to a peer without opening a stream to it   Source   Edit
method dial(s: Switch; peerId: PeerId; addrs: seq[MultiAddress];
            protos: seq[string]; forceDial = false): Future[Connection] {.
    public, ...raises: [], tags: [RootEffect].}
Connected to a peer and open a stream with the specified protos   Source   Edit
method dial(s: Switch; peerId: PeerId; protos: seq[string]): Future[Connection] {.
    public, ...raises: [], tags: [RootEffect].}
Open a stream to a connected peer with the specified protos   Source   Edit

Exports

storeConn, ConnManager, PeerEventKind, selectConn, contains, getStream, addPeerEventHandler, new, ConnEventKind, PeerEventHandler, selectMuxer, contains, removePeerEventHandler, storeMuxer, ConnEvent, connCount, ConnEventHandler, addConnEventHandler, triggerConnEvent, removeConnEventHandler, contains, triggerPeerEvents, selectConn, PeerEvent, TooManyConnectionsError, getStream, trackConnection, close, MaxConnectionsPerPeer, getStream, getOutgoingSlot, dropPeer, getIncomingSlot, release, MaxConnections, ConnectionSlot, newLPStreamWriteError, getProtoHeader, ProtoHeader, shortLog, init, random, $, MaError, ephemeral, MaPatternOp, HTTP, initVBuffer, getProtoHeader, MaxSizeError, LPStreamError, ==, getLen, ECDHEScheme, shortLog, MsgSize, init, closed, shuffle, toString, random, init, VBuffer, Secret, peekVarint, random, handshake, $, validate, mapOr, upgradeOutgoing, hash, Secure, UpgradeFailedError, IdentityInvalidMsgError, maxInlineKeyLength, addHandler, TranscoderDNS, QUIC, ProtoVersion, [], init, ephemeral, getRequiredField, getField, init, supported, getWrapped, write, public, MAKind, getBytes, write, init, checkFieldNumber, init, codec, getRepeatedField, matchPartial, push, getBytes, ==, init, readLp, TimeoutHandler, initVBuffer, start, atEof, identify, peekSeq, update, payloadType, <=, init, $, IP, protoAddress, newRng, SupportedWireTypes, ==, SecureConn, checkValid, getPublicKey, decodeProposal, len, CircuitRelay, extractPublicKey, mapAnd, new, verify, newLPStreamEOFError, init, DNSADDR, Ls, IdentifyPushHandler, libp2p_pki_schemes, write, new, PeerId, WSS, hash, writePacked, closeImpl, identify, toBytes, shortLog, encode, len, init, protoName, LPProtoHandler, ==, toRawBytes, IdentifyPush, MaPattern, TranscoderIP6Zone, initProtoBuffer, newLPStreamReadError, init, ProtoBuffer, list, match, <, CryptoResult, shcopy, ProtoResult, WebRTCDirect, init, Upgrade, UDP, TranscoderOnion, goffset, IdentifyNoPubKeyError, write, init, isEmpty, writeArray, writeLp, decode, new, decode, LPStreamIncompleteError, LPStreamEOFError, IP6, shortLog, initVBuffer, ProtoFlags, PKScheme, payload, write, init, TCP, PrivateKey, getBytes, start, newLPStreamIncorrectDefect, close, high, &=, PeerInfoError, hash, newLPStreamClosedError, readOnce, handle, TranscoderIP4, init, initProtoBuffer, toException, DNS, key, readVarint, upgrade, StreamTracker, HandlerHolder, >, SecureConnTrackerName, KeyPair, finish, init, toOpenArray, cmp, DNSANY, peekArray, formatItIMPL, formatItIMPL, initStream, formatItIMPL, Signature, formatItIMPL, toBytes, DigestSheme, IPFS, getField, shortLog, readOnce, init, init, secure, isEmpty, MultiAddress, ProtoScalar, shortLog, getWrapped, LPStreamIncorrectDefect, MSCodec, hex, expandItIMPL, protocols, codec=, HTTPS, UNIX, tryAndWarn, WebSockets, LPError, getPtr, write, TranscoderIP6, init, readSeq, addHandler, encode, formatItIMPL, MaResult, init, ProtoField, IdentifyPushCodec, toBytes, writeSeq, stretchKeys, Codec, DNS6, [], decode, IpTransportProtocol, libp2p_failed_upgrade, init, allFuturesThrowing, IP4, TranscoderPort, isEnough, write, getField, createExchange, >=, mac, finish, payloadDomain, $, Matcher, IdentityNoMatchError, init, LPStreamLimitError, TranscoderOnion3, SignedPayload, closeImpl, toBytes, protoArgument, secure, newLPStreamLimitError, write, keyOpenArray, init, match, $, closeImpl, isEmpty, LPStreamReadError, new, getRequiredRepeatedField, init, newLPStreamIncompleteError, newLPStreamReadError, readMessage, initProtoBuffer, MAProtocol, getPackedRepeatedField, initStream, contains, getField, shortLog, DNS4, Connection, readArray, selectBest, write, P2PPattern, Envelope, hasPublicKey, toException, init, isEnough, init, Reliable, MultiStreamError, hex, write, WS, AgentVersion, MultistreamSelect, encode, LPProtocol, init, init, init, getField, match, getField, writeLPVarint, iv, onUpgrade, DefaultConnectionTimeout, MaxMessageSize, readLine, Eof, CryptoError, getField, Identify, append, init, PeerRecord, isUpgraded, decodeExchange, SupportedSchemes, getRepeatedField, LPStreamWriteError, getField, select, Unreliable, SupportedSchemesInt, random, checkFutures, macOpenArray, init, validate, $, mapEq, getField, init, write, LPStreamTrackerName, Na, select, concat, TranscoderP2P, PeerInfo, AddressInfo, ConnectionTrackerName, sign, new, write, EnvelopeError, LPStream, IdentifyInfo, IdentifyError, addHandler, encode, len, createProposal, MaPatResult, Direction, init, InvalidVarintError, shortLog, &, init, write, getBytes, write, upgradeIncoming, init, UTP, init, PublicKey, decodeMsg, writeLp, getRawBytes, writePBVarint, ProtoFieldKind, readExactly, getRepeatedField, ProtoError, new, init, IdentifyCodec, initStream, getField, readVarint, ivOpenArray, closeWithEOF, init, RsaDefaultKeySize, orError, vsizeof, protoCode, stop, MaInvalidAddress, select, LPStreamClosedError, items, write, getOrder, [], TranscoderUnix, SignedPeerRecord, stop, join, writeVarint, toException, toException, DialFailedError, addTransport, allFuturesThrowing, tryDial, dial, tryDial, addTransport, Dial, dial, Dialer, checkFutures, tryAndWarn, new, connect, dial, dial, connect, LPError, SPRBook, PeerBook, ProtoBook, AddressBook, ProtoVersionBook, SeqPeerBook, KeyBook, PeerBookChangeHandler, AgentBook, new, PeerStore