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