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/server, protocols/connectivity/relay/relay, protocols/connectivity/relay/client, protocols/connectivity/relay/rtransport, connmanager, upgrademngrs/muxedupgrade, observedaddrmanager, nameresolving/nameresolver, errors, utility, services/wildcardresolverservice
Types
SecureProtocol {.pure.} = enum Noise
- 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: Opt[int] autonat: bool circuitRelay: Relay rdv: RendezVous services: seq[Service] observedAddrManager: ObservedAddrManager enableWildcardResolver: bool
- Source Edit
TransportProvider {.public.} = proc (upgr: Upgrade): Transport {....gcsafe, raises: [].}
- 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").expect( "valid address"); 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: [LPError], public, ...raises: [].}
- Helper for common switch configurations. Source Edit
proc withAddress(b: SwitchBuilder; address: MultiAddress; enableWildcardResolver: bool = true): 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]; enableWildcardResolver: bool = true): 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 withObservedAddrManager(b: SwitchBuilder; observedAddrManager: ObservedAddrManager): SwitchBuilder {. ...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 withServices(b: SwitchBuilder; services: seq[Service]): SwitchBuilder {. ...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
-
DNS_OR_IP, AlreadyExpectingConnectionError, removePeerEventHandler, shortLog, init, random, new, UDP_DNS, $, MaxConnectionsPerPeer, ephemeral, dial, decode, MaPatternOp, WS_DNS, initVBuffer, <=, decode, MaxSizeError, DialFailedError, handler=, ==, ConnectionSlot, handler, filterIt, ECDHEScheme, shortLog, dial, readVarint, init, closed, addConnEventHandler, [], new, macOpenArray, random, init, new, Secret, peekVarint, payload, handshake, MaxConnections, $, validate, mapOr, dial, AgentBook, MaError, secure, UpgradeFailedError, IdentityInvalidMsgError, maxInlineKeyLength, addHandler, TranscoderDNS, QUIC, init, ephemeral, withValue, key, dial, writeLp, removeConnEventHandler, getWrapped, getBytes, public, MAKind, readMessage, init, getField, valueOr, DNSANY, codec, getRepeatedField, matchPartial, addObservation, stop, removePeerEventHandler, push, len, trackConnection, ==, init, readLp, HTTP, initVBuffer, VBuffer, start, atEof, PeerEventKind, getOutgoingSlot, peekSeq, SeqPeerBook, toOpt, fullAddrs, payloadType, LPStreamError, init, $, IP, protoAddress, QUIC_V1_IP, newRng, ==, withValue, mount, SecureConn, checkValid, handle, getPublicKey, CircuitRelay, WebSockets, libp2p_failed_upgrades_incoming, extractPublicKey, mapAnd, maErr, UDP_IP, ConnManager, newLPStreamEOFError, selectMuxer, init, connCount, write, DNSADDR, handler, AddressMapper, IdentifyPushHandler, libp2p_pki_schemes, init, write, new, WSS, QUIC_V1, TCP_IP, selectMuxer, QUIC_V1_DNS, init, closeImpl, Identify, toBytes, TCP_DNS, shortLog, encode, len, capLen, init, protoName, protoArgument, PeerEventHandler, LPProtoHandler, Secure, toRawBytes, IdentifyPush, getStream, TranscoderIP6Zone, $, init, maxIncomingStreams, slotsAvailable, WSS_DNS, list, match, writeLPVarint, CryptoResult, WebSockets_DNS, init, WebRTCDirect, init, init, $, UDP, ProtoVersionBook, PeerInfo, Dialer, disconnect, TranscoderOnion, dial, StreamTracker, IdentifyNoPubKeyError, write, init, LPStreamResetError, run, writeArray, IdentityNoMatchError, new, toString, LPStreamIncompleteError, connectedPeers, LPStreamEOFError, maxIncomingStreams=, IP6, shortLog, new, initVBuffer, decode, PKScheme, init, new, release, random, triggerConnEvent, triggerPeerEvents, init, connect, newSwitch, init, Connection, write, TCP, PrivateKey, dropPeer, getBytes, start, write, init, close, &=, PeerInfoError, newLPStreamClosedError, random, compilesOr, close, trackMuxer, TranscoderIP4, init, $, toException, DNS, init, init, Upgrade, UTP, goffset, HandlerHolder, getRawBytes, >, SecureConnTrackerName, KeyPair, init, init, high, SPRBook, Dial, cmp, peekArray, PeerStore, formatItIMPL, formatItIMPL, initStream, QUIC_DNS, formatItIMPL, Signature, contains, codec=, exclIfIt, hash, formatItIMPL, getStream, DigestSheme, IPFS, getField, shortLog, readOnce, exceptionToAssert, isEmpty, ConnEventKind, shortLog, getWrapped, connect, contains, hex, expandItIMPL, protocols, bytes, DefaultMaxIncomingStreams, HTTPS, UNIX, encode, TooManyConnectionsError, LPError, addTransport, IdentifyCodec, TLS_WS, TranscoderIP6, init, readSeq, addHandler, storeMuxer, addConnEventHandler, formatItIMPL, dial, PeerEvent, supported, MaResult, init, connect, PeerBookChangeHandler, getStream, writeSeq, ConnEvent, stretchKeys, ==, DNS6, [], IpTransportProtocol, init, [], IP4, TranscoderPort, write, safeConvert, addPeerEventHandler, >=, expectConnection, payloadDomain, update, $, identify, start, withValue, handle, readOnce, init, LPStreamLimitError, TranscoderOnion3, SignedPayload, mac, closeImpl, toBytes, protoArgument, secure, newLPStreamLimitError, write, keyOpenArray, match, parseFullAddress, dial, isEmpty, connectedPeers, new, connect, init, newLPStreamIncompleteError, MAProtocol, newLPStreamResetError, initStream, shortLog, DNS4, MultiAddress, WS_IP, readArray, selectBest, getBytes, P2PPattern, Envelope, connect, hasPublicKey, AddressBook, toException, contains, init, isEnough, getConnections, Reliable, addrs, hex, removeConnEventHandler, closeImpl, WS, AgentVersion, init, MultistreamSelect, encode, LPProtocol, init, init, getField, match, TcpOnion3, <, iv, DefaultConnectionTimeout, readLine, Eof, CryptoError, addPeerEventHandler, append, MaPattern, IdentifyPushCodec, parseFullAddress, WSS_IP, LPStreamConnDownError, PeerRecord, readVarint, SupportedSchemes, getField, select, Unreliable, SupportedSchemesInt, random, checkFutures, handler=, hash, PeerBook, shuffle, validate, upgrade, addTransport, ProtoVersion, protoCode, mapEq, Onion3, stop, write, guessDialableAddr, select, concat, TranscoderP2P, AddressInfo, ConnectionTrackerName, sign, new, finish, write, EnvelopeError, LPStream, hash, IdentifyInfo, IdentifyError, addHandler, encode, len, newLPStreamRemoteClosedError, PeerId, MaPatResult, isConnected, Direction, init, InvalidVarintError, Switch, shortLog, &, init, write, getBytes, write, dial, init, toBytes, verify, data, init, getMostObservedProtosAndPorts, QUIC_IP, init, ConcurrentUpgrades, tryDial, PublicKey, ConnEventHandler, WebSockets_IP, decodeMsg, writeLp, addTransport, writePBVarint, ProtoBook, readExactly, newLPStreamConnDownError, new, new, init, initStream, getField, KeyBook, ivOpenArray, connect, closeWithEOF, TimeoutHandler, LPStreamTrackerName, orError, new, ObservedAddrManager, getField, LPStreamRemoteClosedError, libp2p_failed_upgrades_outgoing, MultiStreamError, stop, MaInvalidAddress, select, LPStreamClosedError, RsaDefaultKeySize, getIncomingSlot, Service, items, write, toBytes, getOrder, TranscoderUnix, LastSeenBook, setup, SignedPeerRecord, tryDial, Matcher, stop, join, writeVarint, formatItIMPL, exclIfIt, hash, shortLog, random, $, write, PeerId, ==, getField, <=, capLen, init, validate, init, match, <, getBytes, maxInlineKeyLength, write, withValue, safeConvert, shortLog, >=, withValue, public, shortLog, compilesOr, toBytes, filterIt, match, valueOr, init, init, init, toOpt, init, withValue, hasPublicKey, >, hex, len, exceptionToAssert, cmp, extractPublicKey, shortLog, UDP_DNS, ephemeral, MaPatternOp, <=, filterIt, shortLog, $, validate, hash, TLS_WS, TranscoderDNS, init, ephemeral, MAKind, getField, init, getRepeatedField, getBytes, len, &, peekSeq, fullAddrs, init, QUIC_V1_IP, withValue, getPublicKey, exceptionToAssert, new, DNSANY, DNSADDR, AddressMapper, WSS, init, toBytes, TCP_DNS, shortLog, encode, len, supported, ==, $, WSS_DNS, <, $, PeerInfo, TranscoderOnion, write, key, writeArray, PeerId, IP6, shortLog, payload, init, TCP, PrivateKey, getBytes, init, &=, init, $, getRawBytes, KeyPair, update, hash, contains, DNS4, isEmpty, data, HTTPS, QUIC_DNS, TranscoderIP6, encode, MaResult, DNS6, [], IpTransportProtocol, TranscoderPort, >=, payloadDomain, TranscoderOnion3, protoArgument, keyOpenArray, match, WebSockets_DNS, isEmpty, init, selectBest, Envelope, init, init, Reliable, addrs, init, getField, match, CryptoError, append, init, parseFullAddress, checkFutures, shuffle, init, validate, protoCode, TranscoderP2P, sign, getBytes, encode, len, TranscoderIP6Zone, shortLog, getBytes, QUIC_IP, protoArgument, getField, MultiAddress, readVarint, orError, MaInvalidAddress, writeVarint, items, getOrder, TranscoderUnix, SignedPeerRecord, DNS_OR_IP, init, decode, random, MaError, finish, decode, matchPartial, WS_DNS, initVBuffer, ==, ECDHEScheme, init, [], random, Secret, peekVarint, random, mapOr, bytes, maxInlineKeyLength, QUIC, withValue, mac, libp2p_pki_schemes, WS_IP, public, write, init, valueOr, init, HTTP, initVBuffer, TcpOnion3, write, toOpt, payloadType, $, IP, protoAddress, MaPattern, newRng, checkValid, WebSockets, CircuitRelay, extractPublicKey, mapAnd, maErr, UDP_IP, init, ==, init, write, QUIC_V1, TCP_IP, readSeq, capLen, protoName, toRawBytes, toException, match, writeLPVarint, CryptoResult, parseFullAddress, init, WebRTCDirect, init, UDP, decode, initVBuffer, PKScheme, random, init, write, init, write, PeerInfoError, compilesOr, TranscoderIP4, toException, DNS, goffset, >, init, high, toString, init, cmp, init, formatItIMPL, formatItIMPL, Signature, exclIfIt, toBytes, DigestSheme, IPFS, getField, hex, protocols, UNIX, LPError, init, init, toBytes, writeSeq, stretchKeys, ==, init, [], IP4, safeConvert, init, withValue, SignedPayload, toBytes, $, init, MAProtocol, readArray, P2PPattern, hasPublicKey, isEnough, hex, WS, encode, init, init, getField, iv, WSS_IP, peekArray, PeerRecord, SupportedSchemes, getField, Unreliable, SupportedSchemesInt, random, macOpenArray, mapEq, Onion3, concat, AddressInfo, init, write, EnvelopeError, MaPatResult, QUIC_V1_DNS, init, write, write, UTP, verify, init, PublicKey, WebSockets_IP, VBuffer, writePBVarint, ivOpenArray, RsaDefaultKeySize, write, DNS_OR_IP, shortLog, random, UDP_DNS, $, MaError, ephemeral, MaPatternOp, ==, WS_DNS, initVBuffer, <=, decode, MaxSizeError, filterIt, ECDHEScheme, shortLog, init, closed, [], shuffle, random, VBuffer, Secret, peekVarint, random, $, validate, init, bytes, maxInlineKeyLength, TranscoderDNS, QUIC, [], ephemeral, withValue, finish, WS_IP, public, MAKind, decode, write, write, init, valueOr, getRepeatedField, matchPartial, libp2p_pki_schemes, getBytes, WebSockets, init, readLp, HTTP, initVBuffer, atEof, LPStreamTrackerName, peekSeq, toOpt, fullAddrs, payloadType, LPStreamError, init, $, IP, protoAddress, QUIC_V1_IP, newRng, ==, withValue, checkValid, mac, getPublicKey, exceptionToAssert, len, CircuitRelay, extractPublicKey, mapAnd, new, maErr, hash, UDP_IP, new, newLPStreamEOFError, init, DNSADDR, mapOr, AddressMapper, key, write, PeerId, WSS, LPStream, QUIC_V1, TCP_IP, hash, init, closeImpl, readSeq, toBytes, TCP_DNS, shortLog, encode, capLen, protoName, ==, toRawBytes, MaPattern, init, WSS_DNS, match, writeLPVarint, CryptoResult, parseFullAddress, init, WebRTCDirect, MAProtocol, init, UDP, TranscoderOnion, StreamTracker, write, init, LPStreamResetError, writeArray, LPStreamIncompleteError, [], LPStreamEOFError, IP6, shortLog, initVBuffer, PKScheme, init, toString, payload, init, Connection, write, init, TCP, PrivateKey, getBytes, write, init, &=, PeerInfoError, newLPStreamClosedError, random, compilesOr, close, TranscoderIP4, init, toException, DNS, init, init, UTP, goffset, readVarint, getRawBytes, >, KeyPair, init, high, cmp, DefaultConnectionTimeout, formatItIMPL, formatItIMPL, formatItIMPL, Signature, exclIfIt, formatItIMPL, toBytes, DigestSheme, IPFS, readOnce, init, isEmpty, data, shortLog, hex, protocols, init, HTTPS, QUIC_DNS, len, LPError, TLS_WS, sign, encode, supported, update, MaResult, init, TimeoutHandler, toBytes, writeSeq, &, DNS6, IpTransportProtocol, IP4, TranscoderPort, safeConvert, getField, init, >=, init, payloadDomain, $, withValue, init, LPStreamLimitError, TranscoderOnion3, SignedPayload, init, toBytes, protoArgument, newLPStreamLimitError, write, keyOpenArray, QUIC_V1_DNS, match, parseFullAddress, $, isEmpty, writeLp, init, newLPStreamIncompleteError, newLPStreamResetError, initStream, contains, stretchKeys, getField, shortLog, DNS4, getWrapped, readArray, selectBest, write, P2PPattern, Envelope, hasPublicKey, toException, init, isEnough, Reliable, addrs, hex, closeImpl, getBytes, decode, WS, init, encode, init, readVarint, getField, match, <, iv, readLine, Eof, CryptoError, verify, append, DNSANY, WSS_IP, LPStreamConnDownError, peekArray, UNIX, PeerRecord, init, SupportedSchemes, getField, Unreliable, SupportedSchemesInt, random, checkFutures, macOpenArray, init, validate, $, protoCode, mapEq, Onion3, TcpOnion3, hash, concat, TranscoderP2P, PeerInfo, AddressInfo, ConnectionTrackerName, TranscoderIP6, init, write, EnvelopeError, encode, len, newLPStreamRemoteClosedError, TranscoderIP6Zone, MaPatResult, Direction, init, InvalidVarintError, shortLog, ==, init, write, getBytes, write, init, QUIC_IP, PublicKey, WebSockets_IP, writeLp, writePBVarint, readExactly, protoArgument, newLPStreamConnDownError, WebSockets_DNS, initStream, getField, MultiAddress, ivOpenArray, closeWithEOF, orError, getField, LPStreamRemoteClosedError, MaInvalidAddress, LPStreamClosedError, RsaDefaultKeySize, items, write, getOrder, TranscoderUnix, SignedPeerRecord, join, writeVarint, mapAnd, maErr, writeSeq, DNS_OR_IP, UDP_IP, IP6, DNSANY, exclIfIt, hash, init, UDP_DNS, append, MaError, IPFS, data, WSS_IP, TranscoderOnion3, HTTPS, peekArray, MaPatternOp, CircuitRelay, isEmpty, QUIC_V1, WS_DNS, initVBuffer, TCP_IP, QUIC_V1_IP, contains, matchPartial, protocols, ==, Unreliable, readSeq, checkFutures, UNIX, QUIC_DNS, len, LPError, capLen, init, protoName, protoArgument, validate, TranscoderIP6, encode, protoCode, mapEq, [], MaPattern, TranscoderIP6Zone, $, MaResult, init, peekVarint, TranscoderP2P, protoArgument, initVBuffer, toException, init, TCP_DNS, mapOr, WSS_DNS, writeLPVarint, WebSockets_IP, compilesOr, WebRTCDirect, DNS6, WebSockets, TLS_WS, UDP, [], MaPatResult, QUIC, TranscoderOnion, QUIC_V1_DNS, IP4, TranscoderPort, UTP, withValue, safeConvert, shortLog, items, isEmpty, writeArray, WebSockets_DNS, WS_IP, withValue, public, MAKind, [], write, shortLog, DNSADDR, WSS, &, QUIC_IP, TranscoderDNS, initVBuffer, filterIt, match, TranscoderUnix, $, write, writePBVarint, valueOr, HTTP, TCP, IpTransportProtocol, finish, VBuffer, init, init, Onion3, TcpOnion3, init, getField, MultiAddress, &=, MAProtocol, readVarint, toOpt, init, $, IP, protoAddress, DNS4, readArray, TranscoderIP4, withValue, getRepeatedField, P2PPattern, MaInvalidAddress, toException, isEnough, concat, peekSeq, Reliable, hex, DNS, len, WS, high, toString, exceptionToAssert, writeVarint, bytes, Signature, exclIfIt, shortLog, toBytes, DigestSheme, ephemeral, init, filterIt, toRawBytes, sign, SupportedSchemesInt, ECDHEScheme, macOpenArray, Secret, $, write, init, selectBest, init, ephemeral, withValue, safeConvert, init, init, withValue, public, init, getField, valueOr, init, toBytes, random, init, getBytes, getBytes, toOpt, init, newRng, withValue, getPublicKey, init, random, init, exceptionToAssert, init, init, init, getField, iv, CryptoError, ==, verify, init, key, SupportedSchemes, RsaDefaultKeySize, toBytes, capLen, shuffle, supported, write, ==, libp2p_pki_schemes, random, getRawBytes, random, keyOpenArray, CryptoResult, stretchKeys, init, write, init, shortLog, init, PublicKey, mac, shortLog, PKScheme, init, PrivateKey, getBytes, ivOpenArray, write, compilesOr, orError, $, write, goffset, getOrder, KeyPair, toException, toException, checkFutures, LPError