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[MuxerProvider]
  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 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

Exports

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