This module contains a Switch Building helper.
Example:
let switch = SwitchBuilder.new() .withRng(rng) .withAddresses(multiaddress) # etc .build()
Imports
-
switch, peerid, peerinfo, stream/connection, multiaddress, crypto/crypto, transports/transport, transports/tcptransport, muxers/muxer, muxers/mplex/mplex, muxers/yamux/yamux, protocols/identify, protocols/secure/secure, protocols/secure/noise, protocols/rendezvous, protocols/connectivity/autonat, protocols/connectivity/relay/relay, protocols/connectivity/relay/client, protocols/connectivity/relay/rtransport, connmanager, upgrademngrs/muxedupgrade, nameresolving/nameresolver, errors, utility
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] autonat: bool circuitRelay: Relay rdv: RendezVous
- Source Edit
TransportProvider {.public.} = proc (upgr: Upgrade): Transport {....gcsafe, raises: [Defect].}
- Source Edit
Procs
proc new(T: type[SwitchBuilder]): T:type {.public, ...raises: [].}
- 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: [].}
- Helper for common switch configurations. Source Edit
proc withAddress(b: SwitchBuilder; address: MultiAddress): SwitchBuilder {. public, ...raises: [], tags: [].}
-
Set the listening address of the switch
Source Edit
Calling it multiple time will override the value proc withAddresses(b: SwitchBuilder; addresses: seq[MultiAddress]): SwitchBuilder {. public, ...raises: [], tags: [].}
-
Set the listening addresses of the switch
Source Edit
Calling it multiple time will override the value proc withAgentVersion(b: SwitchBuilder; agentVersion: string): SwitchBuilder {. public, ...raises: [], tags: [].}
- Source Edit
proc withAutonat(b: SwitchBuilder): SwitchBuilder {....raises: [], tags: [].}
- Source Edit
proc withCircuitRelay(b: SwitchBuilder; r: Relay = Relay.new()): SwitchBuilder {. ...raises: [], tags: [].}
- Source Edit
proc withMaxConnections(b: SwitchBuilder; maxConnections: int): SwitchBuilder {. public, ...raises: [], 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: [], tags: [].}
- Source Edit
proc withMaxIn(b: SwitchBuilder; maxIn: int): SwitchBuilder {.public, ...raises: [], tags: [].}
- Maximum concurrent incoming connections. Should be used with withMaxOut Source Edit
proc withMaxOut(b: SwitchBuilder; maxOut: int): SwitchBuilder {.public, ...raises: [], tags: [].}
- Maximum concurrent outgoing connections. Should be used with withMaxIn Source Edit
proc withNameResolver(b: SwitchBuilder; nameResolver: NameResolver): SwitchBuilder {. public, ...raises: [], tags: [].}
- Source Edit
proc withNoise(b: SwitchBuilder): SwitchBuilder {.public, ...raises: [], tags: [].}
- Source Edit
proc withPeerStore(b: SwitchBuilder; capacity: int): SwitchBuilder {.public, ...raises: [], tags: [].}
- Source Edit
proc withPrivateKey(b: SwitchBuilder; privateKey: PrivateKey): SwitchBuilder {. public, ...raises: [], 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: [], tags: [].}
- Source Edit
proc withRendezVous(b: SwitchBuilder; rdv: RendezVous = RendezVous.new()): SwitchBuilder {. ...raises: [], tags: [].}
- Source Edit
proc withRng(b: SwitchBuilder; rng: ref HmacDrbgContext): SwitchBuilder {. public, ...raises: [], tags: [].}
- Source Edit
proc withSignedPeerRecord(b: SwitchBuilder; sendIt = true): SwitchBuilder {. public, ...raises: [], tags: [].}
- Source Edit
proc withTcpTransport(b: SwitchBuilder; flags: set[ServerFlags] = {}): SwitchBuilder {. public, ...raises: [], tags: [].}
- Source Edit
proc withTransport(b: SwitchBuilder; prov: TransportProvider): SwitchBuilder {. public, ...raises: [], 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, decodeProposal, removePeerEventHandler, shortLog, random, $, release, MaxConnectionsPerPeer, ephemeral, dial, Na, MaPatternOp, ==, HTTP, initVBuffer, getProtoHeader, MaxSizeError, getLen, ECDHEScheme, shortLog, MsgSize, init, closed, addConnEventHandler, new, macOpenArray, toString, random, init, new, Secret, peekVarint, random, handshake, MaxConnections, $, validate, mapOr, Dial, upgradeOutgoing, MaError, secure, UpgradeFailedError, IdentityInvalidMsgError, maxInlineKeyLength, addHandler, TranscoderDNS, QUIC, $, [], init, ephemeral, getRequiredField, getField, mac, dial, writeLp, removeConnEventHandler, Connection, write, public, MAKind, decode, peekSeq, init, getField, checkFieldNumber, new, init, codec, getRepeatedField, matchPartial, libp2p_pki_schemes, push, getBytes, trackConnection, DNSANY, readLp, finish, TimeoutHandler, initVBuffer, start, ProtoBook, atEof, PeerEventKind, getOutgoingSlot, write, SeqPeerBook, fullAddrs, payloadType, <=, LPStreamError, $, IP, protoAddress, newRng, ==, IdentifyPushCodec, mount, SecureConn, checkValid, getPublicKey, secure, ProtoHeader, parseFullAddress, WebSockets, Secure, extractPublicKey, mapAnd, new, newLPStreamEOFError, selectMuxer, init, connCount, len, ==, DNSADDR, Ls, AddressMapper, IdentifyPushHandler, readVarint, write, new, WSS, close, writePacked, closeImpl, toBytes, shortLog, encode, len, dial, protoName, protoArgument, PeerEventHandler, LPProtoHandler, toRawBytes, identify, IdentifyPush, getStream, MaPattern, createProposal, initProtoBuffer, newLPStreamReadError, init, list, match, writeLPVarint, CryptoResult, parseFullAddress, ProtoResult, WebRTCDirect, init, init, UDP, ProtoVersionBook, PeerInfo, Dialer, disconnect, TranscoderOnion, dial, goffset, IdentifyNoPubKeyError, write, init, LPStreamResetError, isEmpty, writeArray, IdentityNoMatchError, ConnManager, LPStreamIncompleteError, LPStreamEOFError, IP6, shortLog, new, decode, initVBuffer, ProtoFlags, PKScheme, finish, random, triggerConnEvent, triggerPeerEvents, connect, newSwitch, stretchKeys, getWrapped, write, TCP, PrivateKey, dropPeer, addPeerEventHandler, getBytes, start, newLPStreamIncorrectDefect, close, high, &=, PeerInfoError, Identify, newLPStreamClosedError, payload, selectConn, TranscoderIP4, init, $, initProtoBuffer, toException, DNS, init, upgrade, StreamTracker, readVarint, HandlerHolder, >, SecureConnTrackerName, KeyPair, init, addTransport, SPRBook, init, dial, cmp, init, SupportedWireTypes, storeConn, formatItIMPL, initStream, hash, formatItIMPL, Signature, contains, codec=, hash, readSeq, formatItIMPL, getStream, IPFS, getField, shortLog, readOnce, init, init, isEmpty, ConnEventKind, ProtoScalar, shortLog, getWrapped, LPStreamIncorrectDefect, contains, MSCodec, hex, expandItIMPL, protocols, bytes, verify, HTTPS, UNIX, encode, tryAndWarn, TooManyConnectionsError, ConnectionSlot, getPtr, addTransport, IdentifyCodec, TranscoderIP6, addHandler, storeMuxer, Switch, formatItIMPL, PeerEvent, tryDial, supported, MaResult, init, ProtoField, connect, PeerBookChangeHandler, connect, write, getStream, writeSeq, DigestSheme, ConnEvent, ==, decodeMsg, DialFailedError, DNS6, IpTransportProtocol, libp2p_failed_upgrade, toOpenArray, init, [], allFuturesThrowing, IP4, TranscoderPort, isEnough, readMessage, addPeerEventHandler, init, createExchange, >=, init, payloadDomain, $, handle, readOnce, init, LPStreamLimitError, TranscoderOnion3, SignedPayload, toBytes, protoArgument, CircuitRelay, newLPStreamLimitError, write, keyOpenArray, init, match, closeImpl, dial, isEmpty, LPStreamReadError, new, getRequiredRepeatedField, connect, init, newLPStreamIncompleteError, newLPStreamReadError, selectConn, initProtoBuffer, MAProtocol, newLPStreamResetError, getPackedRepeatedField, initStream, contains, init, getField, shortLog, DNS4, readArray, selectBest, write, P2PPattern, Envelope, connect, hasPublicKey, AddressBook, toException, contains, init, isEnough, init, Reliable, init, addrs, hex, removeConnEventHandler, closeImpl, write, WS, AgentVersion, init, init, MultistreamSelect, encode, LPProtocol, init, Matcher, init, key, getField, getField, match, LPStreamTrackerName, <, iv, onUpgrade, DefaultConnectionTimeout, readLine, Eof, CryptoError, getField, append, vsizeof, init, LPStreamConnDownError, peekArray, PeerRecord, init, Codec, getRepeatedField, LPStreamWriteError, getField, select, Unreliable, SupportedSchemesInt, random, checkFutures, LPError, hash, PeerBook, shuffle, MultiStreamError, validate, Upgrade, addTransport, ProtoVersion, protoCode, mapEq, removePeerEventHandler, Onion3, stop, getBytes, TcpOnion3, select, concat, TranscoderP2P, AddressInfo, ConnectionTrackerName, sign, new, isUpgraded, write, EnvelopeError, LPStream, IdentifyInfo, IdentifyError, addHandler, dial, encode, len, newLPStreamRemoteClosedError, PeerId, TranscoderIP6Zone, MaPatResult, isConnected, Direction, ProtoBuffer, write, init, InvalidVarintError, addConnEventHandler, decode, shortLog, formatItIMPL, &, init, write, getBytes, write, dial, upgradeIncoming, UTP, toBytes, init, update, init, ConcurrentUpgrades, PublicKey, ConnEventHandler, SupportedSchemes, VBuffer, writeLp, start, getRawBytes, writePBVarint, ProtoFieldKind, readExactly, getRepeatedField, ProtoError, newLPStreamConnDownError, new, init, write, initStream, getField, MultiAddress, KeyBook, ivOpenArray, connect, closeWithEOF, orError, decodeExchange, getField, LPStreamRemoteClosedError, setupStreamTracker, identify, PeerStore, stop, MaInvalidAddress, select, LPStreamClosedError, RsaDefaultKeySize, getIncomingSlot, items, write, toBytes, getOrder, [], TranscoderUnix, SignedPeerRecord, tryDial, AgentBook, stop, join, writeVarint, formatItIMPL, hash, init, getField, shortLog, >=, getBytes, shortLog, write, $, init, public, shortLog, PeerId, ==, toBytes, <=, match, hex, random, init, write, init, validate, init, init, hasPublicKey, match, <, >, len, maxInlineKeyLength, cmp, extractPublicKey, ProtoHeader, shortLog, ephemeral, MaPatternOp, ==, <=, shortLog, init, $, validate, init, TranscoderDNS, init, ephemeral, getField, MAKind, getField, checkFieldNumber, init, getRepeatedField, getBytes, WebSockets, &, peekSeq, fullAddrs, getProtoHeader, init, getPublicKey, new, DNSANY, DNSADDR, AddressMapper, WSS, init, toBytes, shortLog, encode, len, supported, init, ==, $, finish, <, $, PeerInfo, TranscoderOnion, write, key, writeArray, IP6, shortLog, payload, init, TCP, PrivateKey, getBytes, init, &=, init, $, getRawBytes, KeyPair, update, SupportedWireTypes, hash, init, DNS4, isEmpty, ProtoScalar, HTTPS, tryAndWarn, TranscoderIP6, encode, MaResult, DNS6, [], IpTransportProtocol, toOpenArray, allFuturesThrowing, TranscoderPort, isEnough, write, >=, payloadDomain, $, init, TranscoderOnion3, protoArgument, write, keyOpenArray, match, parseFullAddress, isEmpty, getRequiredRepeatedField, initProtoBuffer, getField, MultiAddress, selectBest, getPtr, Envelope, init, init, Reliable, addrs, ProtoBuffer, readVarint, getField, match, getField, CryptoError, append, vsizeof, init, init, getRepeatedField, checkFutures, shuffle, validate, protoCode, getField, TranscoderP2P, sign, getBytes, encode, len, TranscoderIP6Zone, shortLog, getBytes, init, hash, ProtoFieldKind, protoArgument, orError, decodeExchange, MaInvalidAddress, writeVarint, items, getOrder, [], TranscoderUnix, SignedPeerRecord, getProtoHeader, init, decode, random, MaError, matchPartial, HTTP, initVBuffer, ==, getLen, ECDHEScheme, decode, decode, random, Secret, peekVarint, random, mapOr, bytes, maxInlineKeyLength, QUIC, getRequiredField, mac, public, write, init, libp2p_pki_schemes, initVBuffer, TcpOnion3, write, payloadType, decodeProposal, $, IP, protoAddress, newRng, checkValid, len, CircuitRelay, extractPublicKey, mapAnd, init, write, PeerId, writePacked, readSeq, TranscoderIP4, protoName, toRawBytes, MaPattern, initProtoBuffer, toException, match, writeLPVarint, CryptoResult, parseFullAddress, ProtoResult, WebRTCDirect, UDP, init, isEmpty, initVBuffer, ProtoFlags, PKScheme, random, init, write, init, write, PeerInfoError, initProtoBuffer, toException, DNS, init, goffset, >, init, high, toString, cmp, init, formatItIMPL, formatItIMPL, Signature, toBytes, DigestSheme, IPFS, getField, hex, protocols, UNIX, init, init, ProtoField, toBytes, writeSeq, init, ==, VBuffer, [], IP4, init, createExchange, finish, SignedPayload, toBytes, init, MAProtocol, getPackedRepeatedField, contains, readArray, P2PPattern, hasPublicKey, isEnough, hex, write, WS, init, encode, init, init, iv, getField, peekArray, PeerRecord, SupportedSchemes, getField, Unreliable, SupportedSchemesInt, random, LPError, macOpenArray, mapEq, Onion3, concat, AddressInfo, write, EnvelopeError, createProposal, MaPatResult, init, write, write, UTP, verify, stretchKeys, PublicKey, writePBVarint, getRepeatedField, ProtoError, ivOpenArray, RsaDefaultKeySize, getField, write, newLPStreamWriteError, getProtoHeader, shortLog, init, random, $, MaError, ephemeral, MaPatternOp, HTTP, initVBuffer, getProtoHeader, MaxSizeError, ProtoHeader, ==, getLen, ECDHEScheme, shortLog, isUpgraded, init, closed, finish, [], shuffle, random, init, Secret, peekVarint, random, $, validate, mapOr, init, maxInlineKeyLength, TranscoderDNS, QUIC, [], ephemeral, getRequiredField, getField, init, supported, getWrapped, write, public, MAKind, decode, write, peekSeq, getField, checkFieldNumber, init, getRepeatedField, matchPartial, getBytes, WebSockets, ==, init, readLp, initVBuffer, mac, atEof, write, fullAddrs, payloadType, <=, LPStreamError, init, decode, IP, protoAddress, newRng, DefaultConnectionTimeout, checkValid, getPublicKey, decodeProposal, len, CircuitRelay, extractPublicKey, mapAnd, new, verify, new, newLPStreamEOFError, init, ==, DNSADDR, AddressMapper, init, write, WSS, LPStream, close, writePacked, stretchKeys, closeImpl, readSeq, toBytes, shortLog, encode, TranscoderIP4, init, protoName, toRawBytes, TranscoderIP6Zone, $, initProtoBuffer, newLPStreamReadError, init, ProtoBuffer, match, writeLPVarint, CryptoResult, parseFullAddress, ProtoResult, WebRTCDirect, init, key, UDP, TranscoderOnion, StreamTracker, write, LPStreamResetError, isEmpty, writeArray, writeLp, LPStreamIncompleteError, PeerId, LPStreamEOFError, IP6, shortLog, initVBuffer, ProtoFlags, PKScheme, TimeoutHandler, payload, init, init, Connection, write, TCP, PrivateKey, getBytes, newLPStreamIncorrectDefect, init, &=, PeerInfoError, hash, newLPStreamClosedError, random, init, initProtoBuffer, toException, DNS, init, upgrade, UTP, goffset, finish, getRawBytes, >, KeyPair, init, high, toString, cmp, init, SupportedWireTypes, formatItIMPL, formatItIMPL, formatItIMPL, Signature, formatItIMPL, toBytes, DigestSheme, IPFS, getField, readOnce, libp2p_pki_schemes, isEmpty, MultiAddress, ProtoScalar, shortLog, LPStreamIncorrectDefect, hex, protocols, bytes, HTTPS, tryAndWarn, len, LPError, getPtr, write, sign, init, encode, update, MaResult, ProtoField, toBytes, writeSeq, init, &, DNS6, IpTransportProtocol, toOpenArray, init, allFuturesThrowing, IP4, TranscoderPort, isEnough, getBytes, getField, init, createExchange, >=, payloadDomain, $, init, LPStreamLimitError, TranscoderOnion3, SignedPayload, toBytes, protoArgument, newLPStreamLimitError, write, keyOpenArray, match, parseFullAddress, $, isEmpty, LPStreamReadError, decode, getRequiredRepeatedField, newLPStreamIncompleteError, newLPStreamReadError, initProtoBuffer, MAProtocol, newLPStreamResetError, getPackedRepeatedField, initStream, contains, shortLog, DNS4, readArray, selectBest, write, P2PPattern, Envelope, hasPublicKey, toException, init, isEnough, DNSANY, readVarint, Reliable, addrs, hex, closeImpl, write, WS, encode, init, init, getField, match, getField, <, iv, onUpgrade, readLine, Eof, CryptoError, getField, hash, append, MaPattern, vsizeof, LPStreamConnDownError, peekArray, UNIX, PeerRecord, SupportedSchemes, getRepeatedField, LPStreamWriteError, getField, hash, Unreliable, SupportedSchemesInt, random, checkFutures, macOpenArray, init, validate, $, protoCode, mapEq, getField, Onion3, write, TcpOnion3, concat, TranscoderP2P, PeerInfo, AddressInfo, ConnectionTrackerName, TranscoderIP6, init, write, EnvelopeError, encode, len, newLPStreamRemoteClosedError, createProposal, MaPatResult, Direction, init, InvalidVarintError, shortLog, ==, init, write, getBytes, write, init, init, readVarint, PublicKey, VBuffer, writeLp, writePBVarint, ProtoFieldKind, readExactly, protoArgument, getRepeatedField, ProtoError, newLPStreamConnDownError, init, initStream, ivOpenArray, closeWithEOF, LPStreamTrackerName, orError, decodeExchange, getField, LPStreamRemoteClosedError, setupStreamTracker, MaInvalidAddress, LPStreamClosedError, RsaDefaultKeySize, items, write, getOrder, [], TranscoderUnix, SignedPeerRecord, join, writeVarint, mapAnd, writeLPVarint, DNSANY, hash, append, $, MaError, IP, IPFS, write, getField, TranscoderOnion3, HTTPS, peekArray, MaPatternOp, CircuitRelay, concat, isEmpty, HTTP, getRepeatedField, getField, ProtoScalar, getProtoHeader, contains, WSS, protocols, &, Unreliable, getLen, UNIX, len, 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, Onion3, 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, TcpOnion3, getProtoHeader, ProtoHeader, init, vsizeof, getField, protoAddress, DNS4, readArray, writePacked, getRepeatedField, protoArgument, getPtr, TranscoderIP4, init, initVBuffer, P2PPattern, MaInvalidAddress, initProtoBuffer, isEnough, items, peekSeq, Reliable, hex, [], ProtoBuffer, matchPartial, DNS, len, WS, high, toString, encode, writeVarint, SupportedWireTypes, bytes, 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