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
Service = ref object of RootObj
- Service is internal component of Switch. Service is automatically started and stopped when the Switch starts and stops. Source Edit
ServiceSetupError = object of LPError
- Source Edit
Switch = ref object of Dial peerInfo*: PeerInfo connManager*: ConnManager transports*: seq[Transport] muxedUpgrade*: MuxedUpgrade ms*: MultistreamSelect dialer*: Dialer peerStore*: PeerStore nameResolver*: NameResolver services*: seq[Service] rng*: Rng
- Source Edit
UpgradeError = object of LPError
- Source Edit
Consts
ConcurrentUpgrades = 32
- Source Edit
UpgradeTimeout = (value: 30000000000)
- Source Edit
Procs
proc addConnEventHandler(s: Switch; handler: ConnEventHandler; kind: ConnEventKind) {....raises: [], tags: [], forbids: [].}
-
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) {....raises: [], tags: [], forbids: [].}
-
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[ Stream, (DialFailedError, CancelledError)] {....stackTrace: false, raises: [], gcsafe, raises: [], tags: [RootEffect], forbids: [].}
- Source Edit
proc disconnect(s: Switch; peerId: PeerId): InternalRaisesFuture[void, (CancelledError,)] {....stackTrace: false, raises: [], gcsafe, raises: [], tags: [RootEffect], forbids: [].}
- Disconnect from a peer, waiting for the connection(s) to be dropped Source Edit
proc isConnected(s: Switch; peerId: PeerId): bool {....raises: [], tags: [], forbids: [].}
- returns true if the peer has one or more associated connections Source Edit
proc removeConnEventHandler(s: Switch; handler: ConnEventHandler; kind: ConnEventKind) {....raises: [], tags: [], forbids: [].}
- Source Edit
proc removePeerEventHandler(s: Switch; handler: PeerEventHandler; kind: PeerEventKind) {....raises: [], tags: [], forbids: [].}
- Source Edit
Methods
method addTransport(s: Switch; t: Transport) {....raises: [], tags: [], forbids: [].}
- Source Edit
method connect(s: Switch; address: MultiAddress; allowUnknownPeerId = false): InternalRaisesFuture[ PeerId, (DialFailedError, CancelledError)] {....stackTrace: false, raises: [], gcsafe, raises: [], tags: [RootEffect], forbids: [].}
- Source Edit
method connect(s: Switch; peerId: PeerId; addrs: seq[MultiAddress]; forceDial = false; reuseConnection = true; dir = Direction.Out): InternalRaisesFuture[ void, (DialFailedError, CancelledError)] {....stackTrace: false, raises: [], gcsafe, raises: [], tags: [RootEffect], forbids: [].}
- Source Edit
method dial(s: Switch; peerId: PeerId; addrs: seq[MultiAddress]; protos: seq[string]; forceDial = false): InternalRaisesFuture[ Stream, (DialFailedError, CancelledError)] {....stackTrace: false, raises: [], gcsafe, raises: [], tags: [RootEffect], forbids: [].}
- Source Edit
Exports
-
ConnManager, waitForPeerReady, PeerEventKind, untagPeer, addPeerEventHandler, PeerEventHandler, selectMuxer, contains, AlreadyExpectingConnectionError, expectConnection, connCount, tagPeerDecaying, addConnEventHandler, WatermarkPolicy, maxInOut, contains, PeerEvent, getStream, maxTotal, close, availableSlots, trackMuxer, getOutgoingSlot, release, unprotect, maxConnections, ConnectionLimits, removeConnEventHandler, getStream, DecayFn, tagPeer, getStream, getIncomingSlot, ConnEventKind, new, decayFixed, getConnections, removePeerEventHandler, isProtected, ConnEvent, ConnEventHandler, decayNone, triggerConnEvent, triggerPeerEvents, PeerScoring, storeMuxer, TooManyConnectionsError, trackConnection, bumpDecayingTag, decayLinear, removeDecayingTag, connectedPeers, selectMuxer, dropPeer, protect, peerScore, ConnectionSlot, DNS_OR_IP, LPStreamError, AlreadyExpectingConnectionError, shortLog, init, random, new, UDP_DNS, MaError, libp2p_network_bytes, writeField, ephemeral, decode, replaceIp, unprotect, MaPatternOp, bumpDecayingTag, WS_DNS, initVBuffer, <=, decode, MaxSizeError, removeDecayingTag, LPError, handler, filterIt, protect, ECDHEScheme, shortLog, <, supportsPacked, writeField, closed, LPStream, addConnEventHandler, WatermarkPolicy, [], new, shuffle, random, key, VBuffer, Secret, peekVarint, random, handshake, maxConnections, validate, mapOr, guessDialableAddr, chroniclesFormatItIMPL, computeFieldSize, init, secure, Memory, UpgradeFailedError, publicRoutableAddressPolicy, getPubKey, IdentityInvalidMsgError, maxInlineKeyLength, addHandler, TranscoderDNS, QUIC, ProtoVersion, writeField, [], init, ephemeral, withValue, mac, init, PeerInfoObserver, getIp, removeConnEventHandler, libp2p_pki_schemes, WS_IP, isEnough, MAKind, write, take, init, noPrivateAddressPolicy, codec, getRepeatedField, generate, matchPartial, addObservation, releaseOutgoing, removePeerEventHandler, push, getBytes, peerScore, areAddrsConsistent, trackConnection, ==, init, readFieldInto, readLp, HTTP, initVBuffer, start, Delta, atEof, PeerEventKind, getOutgoingSlot, supportsPacked, peekSeq, TCP_IP4, toOpt, join, fullAddrs, payloadType, decode, $, IP, protoAddress, QUIC_V1_IP, newRng, ==, shortLog, withValue, SecureConn, checkValid, handle, getPublicKey, chroniclesFormatItIMPL, libp2p_multiaddress_exts, len, readFieldInto, getPart, libp2p_failed_upgrades_incoming, releaseIncoming, CircuitRelay, extractPublicKey, mapAnd, maErr, UDP_IP, new, newLPStreamEOFError, selectMuxer, DNSANY, connCount, random, readMessage, DNSADDR, handler, AddressMapper, IdentifyPushHandler, IdentifyPushCodec, write, new, PeerId, notifyObservers, WSS, QUIC_V1, TCP_IP, selectMuxer, computeFieldSize, PeerScoring, init, closeImpl, toCidString, readSeq, toBytes, TCP_DNS, closeWrite, shortLog, wasResetLocally, encode, UDP_IP4, WebSockets, capLen, untagPeer, protoName, PeerEventHandler, LPProtoHandler, secure, ==, toRawBytes, supportsPacked, IdentifyPush, getStream, $, writeField, TCP_IP6, resetImpl, DNS, WSS_DNS, list, match, <, CryptoResult, WebSockets_DNS, init, WebRTCDirect, PeerAddressPolicy, init, upgrade, $, UDP, TranscoderOnion, StreamTracker, waitForPeerReady, write, init, LPStreamResetError, Rng, writeArray, ConnManager, decode, LPStreamIncompleteError, >, LPStreamEOFError, IP6, shortLog, new, release, writeField, initVBuffer, DecayFn, PKScheme, readVarint, new, toString, random, triggerConnEvent, triggerPeerEvents, stretchKeys, accepts, addObserver, Connection, init, generate, TCP, PrivateKey, dropPeer, readFieldInto, write, close, &=, PeerInfoError, canOpenOutgoing, newBearSslRng, QUIC_DNS, maxInOut, newLPStreamClosedError, payload, chroniclesExpandItIMPL, TranscoderMemory, close, trackMuxer, init, $, toException, init, Matcher, Upgrade, goffset, HandlerHolder, getRawBytes, pick, SecureConnTrackerName, KeyPair, init, high, libp2p_failed_upgrades_outgoing, cmp, init, peekArray, initStream, Signature, chroniclesFormatItIMPL, contains, computeFieldSize, tagPeerDecaying, computeFieldSize, removeObserver, supportsPacked, stripPeerId, getStream, DigestSheme, init, IPFS, shortLog, readOnce, init, Secure, resetImpl, isEmpty, toCid, ConnEventKind, MultiAddress, chroniclesFormatItIMPL, contains, hex, protocols, codec=, bytes, selectBest, hash, HTTPS, UNIX, exclIfIt, encode, computeFieldSize, TooManyConnectionsError, supportsPacked, TLS_WS, TranscoderIP6, init, addHandler, storeMuxer, TranscoderIP4, getProtocolArgument, PeerEvent, data, supported, MaResult, init, supportsPacked, getStream, QUIC_V1_IP4, writeSeq, ConnEvent, init, &, $, DNS6, expandAddrs, items, [], IpTransportProtocol, init, IP4, TranscoderPort, getBytes, addPeerEventHandler, init, >=, expectConnection, QUIC_V1_DNS, finish, payloadDomain, $, shortLog, withValue, handle, MuxedStream, canAcceptIncoming, readFieldInto, init, LPStreamLimitError, TranscoderOnion3, ConnectionLimits, SignedPayload, closeImpl, toBytes, protoArgument, decayFixed, newLPStreamLimitError, getBytes, MaPattern, keyOpenArray, len, tagPeer, match, parseFullAddress, toOpt, closeImpl, isEmpty, writeLp, decode, connectedPeers, reset, new, newLPStreamIncompleteError, chroniclesExpandItIMPL, generateBytes, MAProtocol, newLPStreamResetError, reserveOutgoing, initStream, contains, init, shortLog, DNS4, maxTotal, readFieldInto, getWrapped, chroniclesFormatItIMPL, encode, readFieldInto, P2PPattern, getWrapped, Envelope, hasPublicKey, toException, init, Stream, getBytes, init, getConnections, Reliable, addrs, hex, write, toOpt, WS, AgentVersion, MultiStreamError, init, MultistreamSelect, encode, LPProtocol, init, init, init, match, readArray, filterAddrs, writeLPVarint, iv, RawConn, reserveIncoming, readLine, Eof, CryptoError, chroniclesFormatItIMPL, verify, append, init, parseFullAddress, WSS_IP, LPStreamConnDownError, DefaultConnectionTimeout, PeerRecord, init, SupportedSchemes, getField, select, generate, RsaDefaultKeySize, computeFieldSize, Unreliable, SupportedSchemesInt, random, checkFutures, isProtected, handler=, ConnectionSlot, verify, supportsPacked, macOpenArray, init, checkAddresses, validate, $, mapEq, init, Onion3, write, LPStreamTrackerName, toFullAddress, select, pickOne, concat, TranscoderP2P, PeerInfo, AddressInfo, decayNone, ConnectionTrackerName, sign, new, init, write, EnvelopeError, IdentifyInfo, IdentifyError, Identify, encode, len, newLPStreamRemoteClosedError, TranscoderIP6Zone, MaPatResult, Direction, readOnce, init, InvalidVarintError, shortLog, writeField, ==, init, IdentifyNoPubKeyError, write, write, identify, init, UTP, toBytes, readVarint, hash, TimeoutHandler, getMostObservedProtosAndPorts, init, ObservedAddrManager, PublicKey, ConnEventHandler, lookupProtocol, WebSockets_IP, writeLp, decayLinear, update, start, IdentityNoMatchError, writePBVarint, toChunks, readExactly, protoArgument, QUIC_IP, newLPStreamConnDownError, new, init, IdentifyCodec, shortLog, initStream, supportsPacked, ivOpenArray, closeWithEOF, TcpOnion3, orError, getField, LPStreamRemoteClosedError, availableSlots, hash, protoCode, stop, MaInvalidAddress, select, generate, LPStreamClosedError, getIncomingSlot, defaultAddressPolicy, toBytes, getOrder, TranscoderUnix, SignedPeerRecord, stop, writeVarint, dial, dial, dial, Dial, connect, checkFutures, LPError, addTransport, addTransport, connect, toException, new, Dialer, dialAndUpgrade, DialFailedError, negotiateStream, dialAndUpgrade, connect, dial, connect, toException, tryDial, updatePeerInfo, PeerBook, ProtoBook, LastSeenOutboundBook, KeyBook, markPeerConnected, AgentBook, cleanup, contains, startAddressPruning, contains, [], AddressBook, ProtoVersionBook, close, guessDialableAddr, set, markConnected, SPRBook, del, markPeerDisconnected, []=, entries, PeerBookChangeHandler, AddressConfidence, getMostObservedProtosAndPorts, extend, AddressEntry, new, identify, extend, SeqPeerBook, isExpired, []=, PeerStore, len, LastSeenBook, addHandler, [], AddressConfidenceTtls, pruneExpired, del, [], []