libp2p/builders

    Dark Mode
Search:
Group by:
  Source   Edit

This module contains a Switch Building helper.

Example:

let switch =
 SwitchBuilder.new()
 .withRng(rng)
 .withAddresses(multiaddress)
 # etc
 .build()

Types

SecureProtocol {.pure.} = enum
  Noise, Secio {....deprecated.}
  Source   Edit
SwitchBuilder = ref object
  privKey: Option[PrivateKey]
  addresses: seq[MultiAddress]
  secureManagers: seq[SecureProtocol]
  muxers: seq[MuxerBuilder]
  transports: seq[TransportProvider]
  rng: ref HmacDrbgContext
  maxConnections: int
  maxIn: int
  sendSignedPeerRecord: bool
  maxOut: int
  maxConnsPerPeer: int
  protoVersion: string
  agentVersion: string
  nameResolver: NameResolver
  peerStoreCapacity: Option[int]
  isCircuitRelay: bool
  circuitRelayCanHop: bool
  Source   Edit
TransportProvider {.public.} = proc (upgr: Upgrade): Transport {....gcsafe,
    raises: [Defect].}
  Source   Edit

Procs

proc new(T: type[SwitchBuilder]): T:type {.public, ...raises: [Defect].}
Creates a SwitchBuilder   Source   Edit
proc newStandardSwitch(privKey = none(PrivateKey); addrs: MultiAddress |
    seq[MultiAddress] = init(MultiAddress, "/ip4/127.0.0.1/tcp/0").tryGet();
    secureManagers: openArray[SecureProtocol] = [SecureProtocol.Noise];
                       transportFlags: set[ServerFlags] = {}; rng = newRng();
                       inTimeout: Duration = 5.minutes;
                       outTimeout: Duration = 5.minutes;
                       maxConnections = MaxConnections; maxIn = -1; maxOut = -1;
                       maxConnsPerPeer = MaxConnectionsPerPeer;
                       nameResolver: NameResolver = nil;
                       sendSignedPeerRecord = false; peerStoreCapacity = 1000): Switch {.
    ...raises: [Defect, LPError], public, ...raises: [Defect].}
Helper for common switch configurations.   Source   Edit
proc withAddress(b: SwitchBuilder; address: MultiAddress): SwitchBuilder {.
    public, ...raises: [Defect], tags: [].}

Set the listening address of the switch
Calling it multiple time will override the value

  Source   Edit
proc withAddresses(b: SwitchBuilder; addresses: seq[MultiAddress]): SwitchBuilder {.
    public, ...raises: [Defect], tags: [].}

Set the listening addresses of the switch
Calling it multiple time will override the value

  Source   Edit
proc withAgentVersion(b: SwitchBuilder; agentVersion: string): SwitchBuilder {.
    public, ...raises: [Defect], tags: [].}
  Source   Edit
proc withMaxConnections(b: SwitchBuilder; maxConnections: int): SwitchBuilder {.
    public, ...raises: [Defect], tags: [].}
Maximum concurrent connections of the switch. You should either use this, or withMaxIn & withMaxOut   Source   Edit
proc withMaxConnsPerPeer(b: SwitchBuilder; maxConnsPerPeer: int): SwitchBuilder {.
    public, ...raises: [Defect], tags: [].}
  Source   Edit
proc withMaxIn(b: SwitchBuilder; maxIn: int): SwitchBuilder {.public,
    ...raises: [Defect], tags: [].}
Maximum concurrent incoming connections. Should be used with withMaxOut   Source   Edit
proc withMaxOut(b: SwitchBuilder; maxOut: int): SwitchBuilder {.public,
    ...raises: [Defect], tags: [].}
Maximum concurrent outgoing connections. Should be used with withMaxIn   Source   Edit
proc withMplex(b: SwitchBuilder; inTimeout = 5.minutes; outTimeout = 5.minutes;
               maxChannCount = 200): SwitchBuilder {.public, ...raises: [Defect],
    tags: [].}

Uses Mplex as a multiplexer
Timeout is the duration after which a inactive connection will be closed

  Source   Edit
proc withNameResolver(b: SwitchBuilder; nameResolver: NameResolver): SwitchBuilder {.
    public, ...raises: [Defect], tags: [].}
  Source   Edit
proc withNoise(b: SwitchBuilder): SwitchBuilder {.public, ...raises: [Defect],
    tags: [].}
  Source   Edit
proc withPeerStore(b: SwitchBuilder; capacity: int): SwitchBuilder {.public,
    ...raises: [Defect], tags: [].}
  Source   Edit
proc withPrivateKey(b: SwitchBuilder; privateKey: PrivateKey): SwitchBuilder {.
    public, ...raises: [Defect], tags: [].}
Set the private key of the switch. Will be used to generate a PeerId   Source   Edit
proc withProtoVersion(b: SwitchBuilder; protoVersion: string): SwitchBuilder {.
    public, ...raises: [Defect], tags: [].}
  Source   Edit
proc withRelayTransport(b: SwitchBuilder; canHop: bool): SwitchBuilder {.
    ...raises: [Defect], tags: [].}
  Source   Edit
proc withRng(b: SwitchBuilder; rng: ref HmacDrbgContext): SwitchBuilder {.
    public, ...raises: [Defect], tags: [].}
  Source   Edit
proc withSignedPeerRecord(b: SwitchBuilder; sendIt = true): SwitchBuilder {.
    public, ...raises: [Defect], tags: [].}
  Source   Edit
proc withTcpTransport(b: SwitchBuilder; flags: set[ServerFlags] = {}): SwitchBuilder {.
    public, ...raises: [Defect], tags: [RootEffect].}
  Source   Edit
proc withTransport(b: SwitchBuilder; prov: TransportProvider): SwitchBuilder {.
    public, ...raises: [Defect], tags: [].}
Use a custom transport

Example:

let switch =
  SwitchBuilder.new()
  .withTransport(proc(upgr: Upgrade): Transport = TcpTransport.new(flags, upgr))
  .build()
  Source   Edit
proc withYamux(b: SwitchBuilder): SwitchBuilder {....raises: [Defect], tags: [].}
  Source   Edit

Exports

newLPStreamWriteError, getProtoHeader, ==, ProtoHeader, removePeerEventHandler, shortLog, random, MaxConnectionsPerPeer, ephemeral, dial, MaPatternOp, HTTP, initVBuffer, getProtoHeader, ==, decodeProposal, ProtoFlags, getLen, ECDHEScheme, shortLog, MsgSize, init, closed, addConnEventHandler, ephemeral, AgentBook, new, shcopy, shuffle, toString, random, init, new, VBuffer, Secret, peekVarint, random, handshake, MaxConnections, validate, mapOr, dial, upgradeOutgoing, MaError, key, secure, UpgradeFailedError, IdentityInvalidMsgError, maxInlineKeyLength, addHandler, TranscoderDNS, QUIC, $, [], init, getRequiredField, getField, dial, writeLp, removeConnEventHandler, libp2p_pki_schemes, getBytes, public, MAKind, peekSeq, write, init, getField, checkFieldNumber, Na, init, codec, getRepeatedField, matchPartial, push, getBytes, ==, init, readLp, TimeoutHandler, initVBuffer, finish, start, ProtoBook, atEof, PeerEventKind, hash, write, SeqPeerBook, payloadType, <=, LPStreamError, init, $, IP, protoAddress, decode, newRng, mount, SecureConn, checkValid, getPublicKey, Secure, len, secure, extractPublicKey, mapAnd, new, newLPStreamEOFError, selectMuxer, connCount, DNSADDR, Ls, IdentifyPushHandler, ConnProvider, write, new, WSS, getField, verify, writePacked, init, closeImpl, toBytes, shortLog, encode, TooManyConnectionsError, dial, supported, init, protoName, PeerEventHandler, LPProtoHandler, ==, toRawBytes, identify, IdentifyPush, getStream, createProposal, $, initProtoBuffer, newLPStreamReadError, init, ProtoBuffer, list, match, writeLPVarint, CryptoResult, MaxSizeError, ProtoResult, WebRTCDirect, init, IdentifyPushCodec, Upgrade, $, UDP, ProtoVersionBook, Dialer, disconnect, TranscoderOnion, goffset, IdentifyNoPubKeyError, write, init, isEmpty, writeArray, writeLp, IdentityNoMatchError, ConnManager, LPStreamIncompleteError, LPStreamEOFError, IP6, shortLog, new, trackIncomingConn, initVBuffer, PKScheme, finish, new, payload, triggerConnEvent, triggerPeerEvents, newSwitch, Connection, write, init, TCP, PrivateKey, dropPeer, addPeerEventHandler, getBytes, start, newLPStreamIncorrectDefect, init, close, high, &=, PeerInfoError, newLPStreamClosedError, selectConn, close, TranscoderIP4, init, $, initProtoBuffer, toException, DNS, removeConnEventHandler, init, upgrade, UTP, StreamTracker, HandlerHolder, getRawBytes, >, SecureConnTrackerName, KeyPair, init, init, addTransport, SPRBook, init, dial, cmp, init, SupportedWireTypes, storeConn, formatItIMPL, initStream, formatItIMPL, Signature, contains, codec=, readSeq, formatItIMPL, getStream, IPFS, shortLog, readOnce, init, DNS4, init, isEmpty, ConnEventKind, ProtoScalar, shortLog, LPStreamIncorrectDefect, contains, MSCodec, hex, expandItIMPL, protocols, init, HTTPS, UNIX, encode, tryAndWarn, len, LPError, getPtr, addTransport, IdentifyCodec, TranscoderIP6, init, addHandler, storeMuxer, Switch, formatItIMPL, Dial, PeerEvent, MaResult, init, ProtoField, connect, PeerBookChangeHandler, getStream, writeSeq, DigestSheme, ConnEvent, decodeMsg, DialFailedError, DNS6, [], IpTransportProtocol, libp2p_failed_upgrade, toOpenArray, allFuturesThrowing, IP4, TranscoderPort, isEnough, write, addPeerEventHandler, createExchange, >=, init, payloadDomain, MaPattern, init, handle, readOnce, init, LPStreamLimitError, removePeerEventHandler, SignedPayload, trackOutgoingConn, toBytes, CircuitRelay, newLPStreamLimitError, write, identify, keyOpenArray, match, $, closeImpl, dial, isEmpty, LPStreamReadError, new, getRequiredRepeatedField, newLPStreamIncompleteError, newLPStreamReadError, write, selectConn, initProtoBuffer, MAProtocol, getPackedRepeatedField, initStream, contains, getField, shortLog, MultiAddress, readArray, selectBest, write, P2PPattern, Envelope, connect, hasPublicKey, AddressBook, toException, contains, init, isEnough, init, readVarint, Reliable, readVarint, hex, closeImpl, write, decode, WS, AgentVersion, isUpgraded, init, MultistreamSelect, encode, LPProtocol, init, init, init, getField, getField, match, <, iv, onUpgrade, DefaultConnectionTimeout, readLine, Eof, CryptoError, getField, append, init, peekArray, PeerRecord, decodeExchange, Codec, getRepeatedField, LPStreamWriteError, getField, select, hash, Unreliable, SupportedSchemesInt, random, checkFutures, dial, PeerBook, macOpenArray, init, validate, addTransport, ProtoVersion, protoCode, mapEq, getField, Matcher, stop, LPStreamTrackerName, hash, select, concat, TranscoderP2P, PeerInfo, mac, AddressInfo, ConnectionTrackerName, sign, new, stretchKeys, write, EnvelopeError, LPStream, Identify, IdentifyInfo, IdentifyError, addHandler, encode, WebSockets, PeerId, TranscoderIP6Zone, MaPatResult, isConnected, Direction, DNSANY, InvalidVarintError, addConnEventHandler, shortLog, formatItIMPL, &, write, getBytes, write, dial, upgradeIncoming, init, toBytes, MultiStreamError, ConcurrentUpgrades, PublicKey, update, ConnEventHandler, SupportedSchemes, start, writePBVarint, ProtoFieldKind, readExactly, protoArgument, getRepeatedField, decode, ProtoError, new, init, readMessage, initStream, KeyBook, ivOpenArray, connect, closeWithEOF, init, MaxMessageSize, orError, vsizeof, getField, stop, MaInvalidAddress, select, LPStreamClosedError, RsaDefaultKeySize, writeVarint, items, write, toBytes, getOrder, TranscoderUnix, SignedPeerRecord, PeerStore, stop, join, formatItIMPL, hash, init, getField, shortLog, >=, getBytes, shortLog, write, init, public, shortLog, PeerId, ==, toBytes, <=, match, hex, init, write, init, validate, $, init, init, hasPublicKey, match, <, >, len, maxInlineKeyLength, cmp, extractPublicKey, decodeProposal, shortLog, $, ephemeral, MaPatternOp, ==, <=, ==, shortLog, init, $, validate, update, init, TranscoderDNS, init, ephemeral, getField, MAKind, getField, checkFieldNumber, init, getRepeatedField, getBytes, WebSockets, &, peekSeq, getProtoHeader, init, getPublicKey, DNSANY, DNSADDR, WSS, toBytes, shortLog, encode, supported, init, ==, $, <, PeerInfo, TranscoderOnion, write, key, finish, writeArray, IP6, shortLog, payload, stretchKeys, TCP, PrivateKey, getBytes, init, &=, $, getRawBytes, KeyPair, SupportedWireTypes, init, DNS4, isEmpty, ProtoScalar, HTTPS, tryAndWarn, TranscoderIP6, encode, MaResult, DNS6, [], IpTransportProtocol, toOpenArray, allFuturesThrowing, TranscoderPort, isEnough, >=, payloadDomain, init, write, keyOpenArray, match, isEmpty, getRequiredRepeatedField, initProtoBuffer, init, getField, MultiAddress, selectBest, getPtr, Envelope, Reliable, ProtoBuffer, init, getField, match, getField, CryptoError, append, vsizeof, init, getRepeatedField, checkFutures, shuffle, init, validate, protoCode, getField, TranscoderP2P, sign, new, getBytes, encode, len, TranscoderIP6Zone, shortLog, getBytes, init, hash, finish, ProtoFieldKind, protoArgument, orError, decodeExchange, MaInvalidAddress, items, getOrder, TranscoderUnix, SignedPeerRecord, writeVarint, getProtoHeader, init, shcopy, random, MaError, decode, matchPartial, HTTP, initVBuffer, getLen, ECDHEScheme, init, decode, random, Secret, peekVarint, mapOr, maxInlineKeyLength, QUIC, getRequiredField, mac, public, write, init, initVBuffer, write, payloadType, ProtoHeader, $, IP, protoAddress, newRng, checkValid, len, CircuitRelay, extractPublicKey, mapAnd, init, init, write, PeerId, writePacked, readSeq, TranscoderIP4, protoName, toRawBytes, MaPattern, initProtoBuffer, toException, init, match, writeLPVarint, CryptoResult, ProtoResult, WebRTCDirect, init, UDP, init, isEmpty, initVBuffer, decode, ProtoFlags, PKScheme, random, init, write, init, write, PeerInfoError, initProtoBuffer, toException, DNS, goffset, >, init, high, toString, cmp, init, formatItIMPL, formatItIMPL, Signature, hash, toBytes, DigestSheme, IPFS, getField, hex, protocols, init, UNIX, init, ProtoField, toBytes, writeSeq, init, ==, init, [], IP4, createExchange, SignedPayload, toBytes, $, init, MAProtocol, getPackedRepeatedField, contains, readArray, P2PPattern, hasPublicKey, isEnough, hex, write, WS, init, encode, init, init, iv, RsaDefaultKeySize, getField, peekArray, PeerRecord, SupportedSchemes, getField, Unreliable, SupportedSchemesInt, random, LPError, macOpenArray, mapEq, libp2p_pki_schemes, concat, AddressInfo, write, EnvelopeError, createProposal, MaPatResult, readVarint, write, write, UTP, verify, init, PublicKey, VBuffer, writePBVarint, getRepeatedField, ProtoError, ivOpenArray, MaxMessageSize, getField, write, newLPStreamWriteError, getProtoHeader, ProtoHeader, shortLog, init, random, $, MaError, ephemeral, MaPatternOp, ==, HTTP, initVBuffer, getProtoHeader, MaxSizeError, decodeProposal, getLen, ECDHEScheme, shortLog, closed, [], shcopy, shuffle, random, init, Secret, peekVarint, random, $, validate, mapOr, init, maxInlineKeyLength, TranscoderDNS, QUIC, init, getRequiredField, getField, supported, write, public, MAKind, getBytes, write, init, getField, checkFieldNumber, init, getRepeatedField, matchPartial, libp2p_pki_schemes, getBytes, len, ==, init, readLp, finish, init, initVBuffer, VBuffer, atEof, LPStreamTrackerName, peekSeq, payloadType, <=, LPStreamError, init, IP, protoAddress, decode, newRng, DefaultConnectionTimeout, checkValid, getPublicKey, WebSockets, CircuitRelay, extractPublicKey, mapAnd, new, hash, newLPStreamEOFError, init, ==, DNSADDR, hash, init, write, WSS, LPStream, writePacked, TimeoutHandler, init, closeImpl, readSeq, toBytes, shortLog, encode, TranscoderIP4, protoName, ==, toRawBytes, TranscoderIP6Zone, $, initProtoBuffer, newLPStreamReadError, init, match, writeLPVarint, CryptoResult, ProtoResult, WebRTCDirect, init, init, UDP, PeerInfo, TranscoderOnion, StreamTracker, write, init, isEmpty, writeArray, writeLp, LPStreamIncompleteError, PeerId, [], LPStreamEOFError, IP6, shortLog, initVBuffer, ProtoFlags, PKScheme, payload, stretchKeys, Connection, write, init, TCP, PrivateKey, getBytes, write, init, &=, PeerInfoError, newLPStreamClosedError, close, init, $, initProtoBuffer, toException, DNS, init, upgrade, goffset, finish, getRawBytes, >, KeyPair, isUpgraded, init, high, toString, cmp, init, SupportedWireTypes, formatItIMPL, formatItIMPL, formatItIMPL, Signature, formatItIMPL, toBytes, DigestSheme, IPFS, mac, readOnce, isEmpty, MultiAddress, ProtoScalar, shortLog, LPStreamIncorrectDefect, hex, protocols, hash, HTTPS, tryAndWarn, LPError, getPtr, write, sign, readVarint, encode, MaResult, init, ProtoField, toBytes, writeSeq, init, &, DNS6, IpTransportProtocol, toOpenArray, allFuturesThrowing, IP4, TranscoderPort, isEnough, write, getField, init, createExchange, >=, init, payloadDomain, $, LPStreamLimitError, SignedPayload, toBytes, newLPStreamLimitError, write, keyOpenArray, match, $, isEmpty, LPStreamReadError, decode, getRequiredRepeatedField, newLPStreamIncompleteError, newLPStreamReadError, initProtoBuffer, MAProtocol, getPackedRepeatedField, initStream, contains, shortLog, DNS4, readArray, selectBest, newLPStreamIncorrectDefect, P2PPattern, Envelope, hasPublicKey, toException, init, isEnough, DNSANY, Reliable, hex, ProtoBuffer, closeImpl, write, decode, WS, init, encode, init, init, init, getField, match, getField, <, iv, onUpgrade, readLine, Eof, CryptoError, getField, append, MaPattern, vsizeof, peekArray, UNIX, PeerRecord, key, SupportedSchemes, getRepeatedField, LPStreamWriteError, getField, RsaDefaultKeySize, Unreliable, SupportedSchemesInt, random, checkFutures, macOpenArray, init, validate, protoCode, mapEq, getField, init, concat, TranscoderP2P, AddressInfo, ConnectionTrackerName, TranscoderIP6, new, write, EnvelopeError, encode, len, MaxMessageSize, createProposal, MaPatResult, Direction, InvalidVarintError, shortLog, write, getBytes, write, UTP, readVarint, verify, init, PublicKey, update, writeLp, writePBVarint, ProtoFieldKind, readExactly, protoArgument, getRepeatedField, ProtoError, init, initStream, getField, ephemeral, ivOpenArray, closeWithEOF, orError, decodeExchange, getField, MaInvalidAddress, LPStreamClosedError, writeVarint, items, write, getOrder, TranscoderUnix, SignedPeerRecord, join, mapAnd, writeLPVarint, MaxMessageSize, DNSANY, hash, append, MaError, IP, IPFS, write, getField, HTTPS, peekArray, MaPatternOp, CircuitRelay, concat, isEmpty, HTTP, getRepeatedField, getField, ProtoScalar, getProtoHeader, contains, WSS, protocols, &, Unreliable, getLen, UNIX, init, protoName, TranscoderDNS, validate, TranscoderIP6, initVBuffer, protoCode, mapEq, [], MaPattern, $, MaPatResult, initProtoBuffer, init, ProtoField, peekVarint, TranscoderP2P, protoArgument, getRequiredRepeatedField, $, mapOr, match, writeSeq, write, ProtoResult, WebRTCDirect, DNS6, initVBuffer, WebSockets, UDP, TranscoderIP6Zone, VBuffer, QUIC, toOpenArray, TranscoderOnion, IP4, TranscoderPort, write, isEnough, getRequiredField, getField, shortLog, readSeq, writeArray, write, UTP, shcopy, init, public, MAKind, [], getField, checkFieldNumber, IP6, shortLog, DNSADDR, ProtoFlags, isEmpty, IpTransportProtocol, getRepeatedField, ==, finish, TranscoderUnix, isEmpty, write, writePBVarint, ProtoFieldKind, TCP, MaResult, finish, ProtoError, &=, init, init, init, MultiAddress, initProtoBuffer, MAProtocol, readVarint, getPackedRepeatedField, getProtoHeader, ProtoHeader, init, $, vsizeof, getField, protoAddress, DNS4, readArray, writePacked, getRepeatedField, getPtr, TranscoderIP4, init, initVBuffer, P2PPattern, MaInvalidAddress, initProtoBuffer, isEnough, items, peekSeq, Reliable, hex, ProtoBuffer, matchPartial, DNS, len, WS, high, toString, encode, writeVarint, SupportedWireTypes, Signature, shortLog, $, toBytes, DigestSheme, init, write, sign, SupportedSchemesInt, decodeExchange, macOpenArray, supported, Secret, $, selectBest, init, getBytes, toRawBytes, init, createExchange, init, getBytes, public, getRawBytes, init, getField, init, toBytes, random, random, init, write, decodeProposal, ephemeral, newRng, write, getPublicKey, getBytes, init, random, ephemeral, init, key, stretchKeys, getField, iv, ==, verify, init, SupportedSchemes, init, libp2p_pki_schemes, toBytes, shuffle, CryptoError, ==, ECDHEScheme, createProposal, mac, write, random, keyOpenArray, CryptoResult, init, init, shortLog, init, shortLog, PKScheme, PublicKey, init, init, PrivateKey, write, ivOpenArray, RsaDefaultKeySize, orError, goffset, getOrder, KeyPair, init, init, toException, toException, allFuturesThrowing, tryAndWarn, checkFutures, LPError