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