libp2p/switch

Search:
Group by:
Source   Edit  

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
Source   Edit  
Switch {.public.} = ref object of Dial
  peerInfo*: PeerInfo
  connManager*: ConnManager
  transports*: seq[Transport]
  ms*: MultistreamSelect
  dialer*: Dial
  peerStore*: PeerStore
  nameResolver*: NameResolver
  services*: seq[Service]
Source   Edit  
UpgradeError = object of LPError
Source   Edit  

Procs

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