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
Imports
-
stream/connection, transports/transport, upgrademngrs/upgrade, upgrademngrs/muxedupgrade, multistream, multiaddress, protocols/protocol, protocols/secure/secure, peerinfo, protocols/identify, muxers/muxer, utils/semaphore, connmanager, nameresolving/nameresolver, peerid, peerstore, errors, utility, dialer
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
Methods
method addTransport(s: Switch; t: Transport) {....raises: [], tags: [].}
- Source Edit
method connect(s: Switch; addrs: seq[MultiAddress]): Future[PeerId] {. ...raises: [], tags: [RootEffect].}
- Connects to a peer and retrieve its PeerId 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
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, init, Secure, UpgradeFailedError, IdentityInvalidMsgError, maxInlineKeyLength, addHandler, TranscoderDNS, QUIC, ProtoVersion, [], ephemeral, getRequiredField, getField, supported, getWrapped, newLPStreamIncorrectDefect, public, MAKind, decode, peekSeq, write, init, getField, checkFieldNumber, codec, getRepeatedField, matchPartial, push, getBytes, ==, key, readLp, TimeoutHandler, initVBuffer, start, atEof, LPStreamTrackerName, Na, write, update, payloadType, <=, $, IP, protoAddress, newRng, SupportedWireTypes, ==, SecureConn, checkValid, mac, getPublicKey, decodeProposal, len, CircuitRelay, extractPublicKey, mapAnd, new, newLPStreamEOFError, DNSADDR, Ls, AddressMapper, IdentifyPushHandler, DNS4, init, write, new, WSS, verify, writePacked, init, init, closeImpl, identify, toBytes, shortLog, encode, len, init, protoName, LPProtoHandler, ==, toRawBytes, IdentifyPush, TranscoderIP6Zone, initProtoBuffer, newLPStreamReadError, init, ProtoBuffer, list, match, <, CryptoResult, ProtoResult, WebRTCDirect, init, Upgrade, UDP, PeerInfo, TranscoderOnion, goffset, IdentifyNoPubKeyError, write, LPStreamResetError, isEmpty, writeArray, writeLp, new, LPStreamIncompleteError, LPStreamEOFError, IP6, shortLog, decode, initVBuffer, ProtoFlags, PKScheme, payload, init, write, TCP, PrivateKey, getBytes, start, write, init, close, high, &=, PeerInfoError, newLPStreamClosedError, readOnce, handle, TranscoderIP4, initProtoBuffer, toException, DNS, init, init, upgrade, UTP, StreamTracker, HandlerHolder, >, SecureConnTrackerName, KeyPair, finish, init, toOpenArray, cmp, peekArray, formatItIMPL, formatItIMPL, initStream, hash, formatItIMPL, Signature, hash, formatItIMPL, toBytes, DigestSheme, IPFS, getField, shortLog, readOnce, libp2p_pki_schemes, secure, isEmpty, ProtoScalar, shortLog, getWrapped, LPStreamIncorrectDefect, MSCodec, hex, expandItIMPL, protocols, codec=, init, hash, HTTPS, UNIX, tryAndWarn, WebSockets, LPError, getPtr, write, TranscoderIP6, readVarint, readSeq, addHandler, encode, formatItIMPL, MaResult, init, ProtoField, IdentifyPushCodec, toBytes, writeSeq, init, Codec, DNS6, [], IpTransportProtocol, libp2p_failed_upgrade, init, allFuturesThrowing, IP4, TranscoderPort, isEnough, write, createExchange, >=, init, payloadDomain, $, Matcher, IdentityNoMatchError, init, LPStreamLimitError, TranscoderOnion3, SignedPayload, closeImpl, toBytes, protoArgument, secure, newLPStreamLimitError, write, keyOpenArray, init, match, decode, $, closeImpl, isEmpty, LPStreamReadError, shcopy, new, getRequiredRepeatedField, init, newLPStreamIncompleteError, newLPStreamReadError, readMessage, initProtoBuffer, MAProtocol, newLPStreamResetError, getPackedRepeatedField, initStream, contains, stretchKeys, getField, shortLog, MultiAddress, Connection, readArray, selectBest, getBytes, P2PPattern, Envelope, hasPublicKey, toException, init, isEnough, init, Reliable, MultiStreamError, addrs, hex, write, WS, AgentVersion, init, MultistreamSelect, encode, LPProtocol, DNSANY, init, init, finish, getField, match, getField, writeLPVarint, iv, onUpgrade, DefaultConnectionTimeout, MaxMessageSize, readLine, Eof, CryptoError, getField, append, MaPattern, init, LPStreamConnDownError, PeerRecord, isUpgraded, decodeExchange, SupportedSchemes, getRepeatedField, LPStreamWriteError, getField, select, Unreliable, SupportedSchemesInt, random, checkFutures, macOpenArray, init, validate, $, mapEq, getField, init, write, Identify, select, concat, TranscoderP2P, AddressInfo, ConnectionTrackerName, sign, new, init, write, EnvelopeError, LPStream, IdentifyInfo, IdentifyError, addHandler, encode, len, newLPStreamRemoteClosedError, createProposal, MaPatResult, Direction, init, InvalidVarintError, shortLog, &, init, write, getBytes, write, upgradeIncoming, init, init, PublicKey, decodeMsg, writeLp, getRawBytes, writePBVarint, ProtoFieldKind, readExactly, getRepeatedField, ProtoError, newLPStreamConnDownError, new, init, IdentifyCodec, initStream, getField, readVarint, ivOpenArray, closeWithEOF, init, RsaDefaultKeySize, orError, vsizeof, LPStreamRemoteClosedError, identify, protoCode, stop, MaInvalidAddress, select, LPStreamClosedError, PeerId, items, write, getOrder, [], TranscoderUnix, SignedPeerRecord, stop, join, writeVarint, toException, toException, addTransport, allFuturesThrowing, dial, new, dial, connect, checkFutures, Dialer, connect, Dial, DialFailedError, dial, connect, tryDial, dial, addTransport, tryDial, tryAndWarn, connect, LPError, SPRBook, PeerBook, ProtoBook, AddressBook, ProtoVersionBook, SeqPeerBook, KeyBook, PeerBookChangeHandler, AgentBook, new, PeerStore