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, shcopy, MaxSizeError, LPStreamError, ==, getLen, ECDHEScheme, shortLog, MsgSize, init, closed, [], shuffle, toString, random, init, VBuffer, Secret, peekVarint, random, handshake, $, validate, mapOr, upgradeOutgoing, hash, init, Secure, UpgradeFailedError, IdentityInvalidMsgError, maxInlineKeyLength, addHandler, TranscoderDNS, QUIC, ProtoVersion, [], init, ephemeral, getRequiredField, getField, init, supported, write, public, MAKind, write, write, init, checkFieldNumber, init, codec, getRepeatedField, matchPartial, push, getBytes, ==, init, readLp, TimeoutHandler, initVBuffer, start, atEof, identify, peekSeq, update, payloadType, <=, init, decode, $, IP, protoAddress, newRng, SupportedWireTypes, SecureConn, checkValid, getPublicKey, decodeProposal, WebSockets, CircuitRelay, extractPublicKey, mapAnd, new, verify, newLPStreamEOFError, init, ==, DNSADDR, Ls, IdentifyPushHandler, libp2p_pki_schemes, write, new, PeerId, WSS, hash, writePacked, init, closeImpl, identify, toBytes, shortLog, encode, len, init, protoName, LPProtoHandler, ==, toRawBytes, IdentifyPush, MaPattern, TranscoderIP6Zone, initProtoBuffer, newLPStreamReadError, init, ProtoBuffer, list, match, <, CryptoResult, ProtoResult, WebRTCDirect, init, Upgrade, UDP, TranscoderOnion, goffset, IdentifyNoPubKeyError, write, isEmpty, writeArray, writeLp, getRawBytes, new, LPStreamIncompleteError, LPStreamEOFError, IP6, shortLog, decode, initVBuffer, ProtoFlags, PKScheme, payload, Connection, write, init, TCP, PrivateKey, getBytes, start, newLPStreamIncorrectDefect, init, close, high, &=, PeerInfoError, hash, newLPStreamClosedError, handle, TranscoderIP4, init, initProtoBuffer, toException, DNS, init, readVarint, upgrade, StreamTracker, HandlerHolder, >, SecureConnTrackerName, KeyPair, init, finish, init, toOpenArray, cmp, DNSANY, peekArray, formatItIMPL, formatItIMPL, initStream, formatItIMPL, Signature, formatItIMPL, toBytes, DigestSheme, IPFS, getField, shortLog, readOnce, key, init, secure, isEmpty, MultiAddress, ProtoScalar, shortLog, LPStreamIncorrectDefect, MSCodec, hex, expandItIMPL, protocols, codec=, HTTPS, UNIX, tryAndWarn, LPError, getPtr, write, TranscoderIP6, init, readSeq, addHandler, encode, formatItIMPL, MaResult, ProtoField, IdentifyPushCodec, toBytes, writeSeq, stretchKeys, Codec, DNS6, IpTransportProtocol, libp2p_failed_upgrade, init, allFuturesThrowing, IP4, TranscoderPort, isEnough, getBytes, getField, createExchange, >=, mac, finish, payloadDomain, $, Matcher, IdentityNoMatchError, init, LPStreamLimitError, SignedPayload, closeImpl, toBytes, protoArgument, secure, newLPStreamLimitError, write, keyOpenArray, match, $, closeImpl, isEmpty, LPStreamReadError, new, getRequiredRepeatedField, newLPStreamIncompleteError, newLPStreamReadError, readOnce, initProtoBuffer, MAProtocol, getPackedRepeatedField, initStream, contains, getField, shortLog, DNS4, readArray, selectBest, write, P2PPattern, Envelope, hasPublicKey, toException, init, isEnough, init, Reliable, MultiStreamError, hex, write, WS, AgentVersion, MultistreamSelect, encode, LPProtocol, init, init, init, init, getField, match, getField, writeLPVarint, iv, onUpgrade, DefaultConnectionTimeout, readLine, Eof, CryptoError, getField, Identify, append, init, PeerRecord, isUpgraded, decodeExchange, SupportedSchemes, getRepeatedField, LPStreamWriteError, getField, 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, &, write, getBytes, write, upgradeIncoming, init, UTP, init, PublicKey, decodeMsg, writeLp, writePBVarint, ProtoFieldKind, readExactly, getRepeatedField, ProtoError, new, init, readMessage, 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, checkFutures, dial, dial, new, Dial, addTransport, Dialer, dial, tryAndWarn, connect, dial, connect, LPError, SPRBook, PeerBook, ProtoBook, AddressBook, ProtoVersionBook, SeqPeerBook, KeyBook, PeerBookChangeHandler, AgentBook, new, PeerStore