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 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 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 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, init, decode, random, MaError, ephemeral, shcopy, MaPatternOp, HTTP, initVBuffer, getProtoHeader, ==, LPStreamError, getLen, ECDHEScheme, shortLog, MsgSize, init, init, closed, readVarint, [], decode, shuffle, toString, random, init, Secret, peekVarint, payload, handshake, handle, $, validate, mapOr, upgradeOutgoing, init, secure, UpgradeFailedError, IdentityInvalidMsgError, maxInlineKeyLength, addHandler, TranscoderDNS, QUIC, ProtoVersion, [], init, getRequiredField, getField, getBytes, public, MAKind, newLPStreamIncorrectDefect, write, init, getField, checkFieldNumber, init, codec, getRepeatedField, matchPartial, push, getBytes, ==, readLp, TimeoutHandler, initVBuffer, atEof, write, payloadType, <=, ProtoHeader, key, $, 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, protoName, LPProtoHandler, toRawBytes, IdentifyPush, TranscoderIP6Zone, $, initProtoBuffer, newLPStreamReadError, init, ProtoBuffer, list, match, <, CryptoResult, ProtoResult, WebRTCDirect, init, Upgrade, $, UDP, TranscoderOnion, goffset, IdentifyNoPubKeyError, write, init, isEmpty, writeArray, writeLp, new, LPStreamIncompleteError, PeerId, LPStreamEOFError, IP6, shortLog, initVBuffer, ProtoFlags, PKScheme, IdentifyPushCodec, random, Connection, write, TCP, PrivateKey, getBytes, write, init, close, high, &=, PeerInfoError, newLPStreamClosedError, TranscoderIP4, init, $, initProtoBuffer, toException, DNS, stretchKeys, init, upgrade, StreamTracker, HandlerHolder, >, SecureConnTrackerName, KeyPair, init, toOpenArray, cmp, peekArray, formatItIMPL, formatItIMPL, initStream, formatItIMPL, Signature, formatItIMPL, toBytes, DigestSheme, finish, IPFS, getField, shortLog, readOnce, libp2p_pki_schemes, secure, isEmpty, ProtoScalar, shortLog, LPStreamIncorrectDefect, MSCodec, hex, expandItIMPL, protocols, codec=, readVarint, HTTPS, UNIX, tryAndWarn, LPError, getPtr, write, 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, ephemeral, payloadDomain, $, IdentityNoMatchError, init, LPStreamLimitError, SignedPayload, mac, closeImpl, toBytes, protoArgument, newLPStreamLimitError, write, MaPattern, keyOpenArray, init, match, closeImpl, isEmpty, LPStreamReadError, getRequiredRepeatedField, newLPStreamIncompleteError, newLPStreamReadError, readOnce, initProtoBuffer, MAProtocol, MaxSizeError, getPackedRepeatedField, initStream, contains, getField, shortLog, DNS4, MultiAddress, readArray, selectBest, peekSeq, Envelope, hasPublicKey, toException, init, isEnough, init, Reliable, hex, write, WS, AgentVersion, init, MultistreamSelect, encode, LPProtocol, init, Matcher, MultiStreamError, getField, getField, match, 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, init, IdentifyCodec, LPStreamTrackerName, identify, select, concat, TranscoderP2P, PeerInfo, AddressInfo, ConnectionTrackerName, sign, new, init, write, EnvelopeError, IdentifyInfo, IdentifyError, addHandler, identify, encode, len, createProposal, MaPatResult, Direction, init, InvalidVarintError, shortLog, &, init, write, getBytes, write, upgradeIncoming, init, UTP, init, PublicKey, decodeMsg, VBuffer, writeLp, getRawBytes, writePBVarint, ProtoFieldKind, readExactly, getRepeatedField, decode, ProtoError, new, init, readMessage, initStream, getField, finish, ivOpenArray, closeWithEOF, init, orError, vsizeof, decodeExchange, 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