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