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
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 services*: seq[Service]
- Source Edit
UpgradeError = object of LPError
- 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 connectedPeers(s: Switch; dir: Direction): seq[PeerId] {....raises: [], tags: [RootEffect].}
- Source Edit
proc dial(s: Switch; peerId: PeerId; addrs: seq[MultiAddress]; proto: string): InternalRaisesFuture[ Connection, (DialFailedError, CancelledError)] {.public(), stackTrace: false, ...raises: [], gcsafe, raises: [], raises: [], tags: [RootEffect].}
- Source Edit
proc dial(s: Switch; peerId: PeerId; proto: string): InternalRaisesFuture[ Connection, (DialFailedError, CancelledError)] {.public(), stackTrace: false, ...raises: [], gcsafe, raises: [], raises: [], tags: [RootEffect].}
- Source Edit
proc disconnect(s: Switch; peerId: PeerId): Future[void] {....gcsafe, public, ...raises: [], tags: [RootEffect].}
- 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: [LPError], public, ...raises: [].}
- mount a protocol to the switch Source Edit
proc newSwitch(peerInfo: PeerInfo; transports: seq[Transport]; secureManagers: openArray[Secure] = []; connManager: ConnManager; ms: MultistreamSelect; peerStore: PeerStore; nameResolver: NameResolver = nil; services = newSeq()): Switch {. ...raises: [LPError], raises: [], tags: [].}
- 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; address: MultiAddress; allowUnknownPeerId = false): InternalRaisesFuture[ PeerId, (DialFailedError, CancelledError)] {.stackTrace: false, ...raises: [], gcsafe, raises: [], raises: [], tags: [RootEffect].}
- Source Edit
method connect(s: Switch; peerId: PeerId; addrs: seq[MultiAddress]; forceDial = false; reuseConnection = true; dir = Direction.Out): InternalRaisesFuture[ void, (DialFailedError, CancelledError)] {.public(), stackTrace: false, ...raises: [], gcsafe, raises: [], raises: [], tags: [RootEffect].}
- Source Edit
method dial(s: Switch; peerId: PeerId; addrs: seq[MultiAddress]; protos: seq[string]; forceDial = false): InternalRaisesFuture[ Connection, (DialFailedError, CancelledError)] {.public(), stackTrace: false, ...raises: [], gcsafe, raises: [], raises: [], tags: [RootEffect].}
- Source Edit
method dial(s: Switch; peerId: PeerId; protos: seq[string]): InternalRaisesFuture[ Connection, (DialFailedError, CancelledError)] {.public(), stackTrace: false, ...raises: [], gcsafe, raises: [], raises: [], tags: [RootEffect].}
- Source Edit
method run(self: Service; switch: Switch): InternalRaisesFuture[void, (CancelledError,)] {.base, stackTrace: false, ...raises: [], gcsafe, raises: [], raises: [], tags: [RootEffect].}
- Source Edit
Exports
-
ConnManager, getStream, PeerEventKind, getStream, addPeerEventHandler, new, ConnEventKind, PeerEventHandler, selectMuxer, getConnections, contains, removePeerEventHandler, expectConnection, ConnEvent, connCount, ConnEventHandler, addConnEventHandler, triggerConnEvent, removeConnEventHandler, contains, triggerPeerEvents, AlreadyExpectingConnectionError, PeerEvent, TooManyConnectionsError, getStream, trackConnection, close, MaxConnectionsPerPeer, connectedPeers, selectMuxer, trackMuxer, getOutgoingSlot, slotsAvailable, dropPeer, getIncomingSlot, storeMuxer, release, MaxConnections, ConnectionSlot, DNS_OR_IP, mac, LPStreamError, AlreadyExpectingConnectionError, shortLog, init, decode, random, new, UDP_DNS, $, MaxConnectionsPerPeer, ephemeral, MaPattern, MaPatternOp, ==, WS_DNS, initVBuffer, <=, MaxSizeError, handler=, LPError, handler, filterIt, ECDHEScheme, shortLog, init, closed, addConnEventHandler, release, [], init, new, shuffle, random, init, new, Secret, peekVarint, random, handshake, handle, MaxConnections, $, validate, mapOr, MaError, init, secure, bytes, UpgradeFailedError, IdentityInvalidMsgError, maxInlineKeyLength, addHandler, TranscoderDNS, QUIC, ProtoVersion, [], init, ephemeral, withValue, init, removeConnEventHandler, WS_IP, public, MAKind, write, write, init, getField, valueOr, codec, getRepeatedField, matchPartial, addObservation, push, getBytes, len, trackConnection, ==, readLp, HTTP, initVBuffer, VBuffer, start, atEof, PeerEventKind, getOutgoingSlot, peekSeq, toOpt, fullAddrs, payloadType, init, $, IP, protoAddress, QUIC_V1_IP, newRng, withValue, init, SecureConn, checkValid, getPublicKey, IdentityNoMatchError, len, libp2p_failed_upgrades_incoming, CircuitRelay, extractPublicKey, mapAnd, new, maErr, hash, UDP_IP, new, newLPStreamEOFError, selectMuxer, DNSANY, connCount, random, readOnce, DNSADDR, handler, AddressMapper, IdentifyPushHandler, write, ConnManager, WSS, QUIC_V1, TCP_IP, close, selectMuxer, init, closeImpl, identify, readSeq, toBytes, TCP_DNS, shortLog, encode, len, capLen, init, protoName, protoArgument, PeerEventHandler, LPProtoHandler, ==, toRawBytes, IdentifyPush, getStream, init, maxIncomingStreams, WSS_DNS, list, match, <, CryptoResult, parseFullAddress, init, WebRTCDirect, init, QUIC_V1_DNS, upgrade, UDP, TranscoderOnion, StreamTracker, IdentifyNoPubKeyError, write, init, LPStreamResetError, writeArray, new, toString, LPStreamIncompleteError, LPStreamEOFError, maxIncomingStreams=, IP6, shortLog, new, initVBuffer, PKScheme, init, new, payload, triggerConnEvent, triggerPeerEvents, init, stretchKeys, write, init, TCP, PrivateKey, dropPeer, getBytes, start, write, init, &=, PeerInfoError, newLPStreamClosedError, TooManyConnectionsError, compilesOr, close, handle, trackMuxer, $, toException, DNS, Upgrade, UTP, goffset, readVarint, HandlerHolder, getRawBytes, >, SecureConnTrackerName, KeyPair, MAProtocol, key, high, init, cmp, init, formatItIMPL, formatItIMPL, initStream, formatItIMPL, Signature, verify, exclIfIt, formatItIMPL, data, getStream, DigestSheme, IPFS, getField, shortLog, readOnce, init, DNS4, init, Secure, isEmpty, ConnEventKind, MultiAddress, shortLog, Connection, contains, hex, expandItIMPL, protocols, codec=, DefaultMaxIncomingStreams, HTTPS, UNIX, encode, QUIC_DNS, WebSockets, write, TLS_WS, TranscoderIP6, init, addHandler, encode, TranscoderIP4, formatItIMPL, PeerEvent, ObservedAddrManager, supported, MaResult, init, getStream, writeSeq, ConnEvent, ==, $, DNS6, [], decode, IpTransportProtocol, IP4, TranscoderPort, safeConvert, addPeerEventHandler, init, >=, expectConnection, payloadDomain, update, $, withValue, IdentifyPushCodec, WebSockets_DNS, LPStreamLimitError, TranscoderOnion3, SignedPayload, closeImpl, toBytes, secure, newLPStreamLimitError, getBytes, keyOpenArray, readVarint, match, parseFullAddress, $, closeImpl, isEmpty, writeLp, connectedPeers, new, init, newLPStreamIncompleteError, readMessage, newLPStreamResetError, initStream, contains, getField, shortLog, removePeerEventHandler, getWrapped, readArray, selectBest, P2PPattern, getWrapped, Envelope, hasPublicKey, toException, contains, init, isEnough, getConnections, Reliable, init, addrs, hex, slotsAvailable, write, WS, AgentVersion, MultistreamSelect, encode, LPProtocol, init, init, init, init, getField, match, getField, writeLPVarint, iv, DefaultConnectionTimeout, new, readLine, Eof, CryptoError, append, init, WSS_IP, LPStreamConnDownError, PeerRecord, SupportedSchemes, select, hash, Unreliable, SupportedSchemesInt, random, checkFutures, handler=, ConnectionSlot, libp2p_failed_upgrades_outgoing, macOpenArray, init, validate, mapEq, libp2p_pki_schemes, Onion3, IdentifyCodec, LPStreamTrackerName, select, concat, TranscoderP2P, PeerInfo, AddressInfo, ConnectionTrackerName, sign, init, write, EnvelopeError, LPStream, IdentifyInfo, IdentifyError, addHandler, Identify, storeMuxer, newLPStreamRemoteClosedError, TranscoderIP6Zone, MaPatResult, Direction, init, InvalidVarintError, decode, shortLog, items, &, init, write, getBytes, write, toBytes, finish, peekArray, TimeoutHandler, getMostObservedProtosAndPorts, QUIC_IP, PublicKey, ConnEventHandler, WebSockets_IP, decodeMsg, writeLp, writePBVarint, readExactly, protoArgument, newLPStreamConnDownError, init, initStream, getField, ivOpenArray, closeWithEOF, TcpOnion3, orError, LPStreamRemoteClosedError, guessDialableAddr, Matcher, protoCode, stop, MaInvalidAddress, select, LPStreamClosedError, RsaDefaultKeySize, PeerId, writeVarint, getIncomingSlot, write, toBytes, getOrder, hash, TranscoderUnix, SignedPeerRecord, MultiStreamError, stop, join, dial, dial, dial, connect, checkFutures, LPError, addTransport, addTransport, connect, toException, new, dial, Dialer, tryDial, DialFailedError, connect, Dial, connect, toException, tryDial, PeerBook, ProtoBook, AddressBook, ProtoVersionBook, KeyBook, LastSeenBook, AgentBook, SPRBook, new, SeqPeerBook, PeerBookChangeHandler, PeerStore