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