libp2p/services/natservice

Search:
Group by:
Source   Edit  

Types

AutonatVersion = enum
  AutonatV1, AutonatV2
Source   Edit  
HolePunchingConfig = object
  maxNumRelays*: int
  onReservation*: OnReservationHandler
  scheduleInterval*: Opt[Duration]
DCUtR hole-punching; drives AutoNAT v1 + AutoRelay internally. Source   Edit  
NATConfig = object
  portMapping*: Opt[PortMappingConfig]
  reachability*: Opt[ReachabilityConfig]
  holePunching*: Opt[HolePunchingConfig]
portMapping is independent; reachability and holePunching are mutually exclusive (HP drives its own AutoNAT v1) and rejected at setup. Source   Edit  
NATService = ref object of Service
  externalIp*: Opt[IpAddress]
Source   Edit  
PortMapperFactory = proc (mode: PortMappingMode): Opt[PortMapper] {....gcsafe,
    raises: [].}
Source   Edit  
PortMappingConfig = object
  case mode*: PortMappingMode
  of ExplicitIp:
    explicitIp*: IpAddress
  of Upnp, NatPmp:
    refreshInterval*: Duration
    discoveryTimeout*: Duration
    leaseDuration*: Duration
Source   Edit  
PortMappingMode = enum
  ExplicitIp, Upnp, NatPmp
Source   Edit  
ReachabilityConfig = object
  version*: AutonatVersion
  scheduleInterval*: Opt[Duration]
  v2ServiceConfig*: Opt[AutonatV2ServiceConfig]
AutoNAT reachability probing. scheduleInterval tunes the v1 cadence; v2ServiceConfig configures the v2 service. Source   Edit  

Consts

DefaultDiscoveryTimeout = (value: 10000000000)
Source   Edit  
DefaultLeaseDuration = (value: 3600000000000)
Source   Edit  
DefaultRefreshInterval = (value: 1800000000000)
Source   Edit  

Procs

proc autonatConfig(version: AutonatVersion;
                   scheduleInterval = Opt.none(Duration);
                   v2ServiceConfig = Opt.none(AutonatV2ServiceConfig)): NATConfig {.
    ...raises: [], tags: [], forbids: [].}
Probe-only AutoNAT (no port-mapping, no hole-punching). Source   Edit  
proc autonatV2Service(self: NATService): Opt[AutonatV2Service] {....raises: [],
    tags: [], forbids: [].}
The live AutoNAT v2 service when reachability uses AutonatV2, else none. Source   Edit  
proc explicitIpConfig(explicitIp: IpAddress): NATConfig {....raises: [], tags: [],
    forbids: [].}
Announce explicitIp as the external IP; no port-mapping is performed. Source   Edit  
proc explicitIpMapped(listenAddrs: seq[MultiAddress]; explicitIp: IpAddress): seq[
    MultiAddress] {....raises: [], tags: [RootEffect], forbids: [].}
For each listen address that carries an IP component matching the family of explicitIp, emit a copy with the IP swapped to explicitIp. Transport, port, and any suffix (e.g. /quic-v1, /ws, /wss, /tls/ws) are preserved. Addresses without an IP component, or with a mismatching family, are dropped. Duplicates (which can arise when the wildcard resolver expands a wildcard listen addr across multiple interfaces sharing the same port) are collapsed. Source   Edit  
proc holePunchingConfig(maxNumRelays: int = 1;
                        onReservation: OnReservationHandler = nil;
                        scheduleInterval = Opt.none(Duration)): NATConfig {.
    ...raises: [], tags: [], forbids: [].}
AutoNAT v1 + AutoRelay + DCUtR. Hole-punching with v2 is not supported. Source   Edit  
proc mergeInto(dst: var NATConfig; src: NATConfig) {....raises: [], tags: [],
    forbids: [].}
Fold src's set concerns into dst; setting one concern twice is a programmer error (build-time misuse), so it fails fast with a Defect. Source   Edit  
proc natPmpConfig(refreshInterval = DefaultRefreshInterval;
                  discoveryTimeout = DefaultDiscoveryTimeout;
                  leaseDuration = DefaultLeaseDuration): NATConfig {....raises: [],
    tags: [], forbids: [].}
Source   Edit  
proc natService(switch: Switch): Opt[NATService] {....raises: [], tags: [],
    forbids: [].}
The switch's NATService, if one was configured. Source   Edit  
proc new(T: typedesc[NATService]; config: NATConfig; rng: Rng;
         portMapperFactory: PortMapperFactory = nil): T:type {....raises: [].}
Source   Edit  
proc setupMappings(self: NATService; listenAddrs: seq[MultiAddress]): InternalRaisesFuture[
    seq[MultiAddress], (CancelledError,)] {....stackTrace: false, raises: [],
    gcsafe, raises: [], tags: [RootEffect], forbids: [].}
Request a mapping for every private listen address; updates externalIp and mappedPorts as a side-effect, and tears down mappings that are no longer needed. Source   Edit  
proc upnpConfig(refreshInterval = DefaultRefreshInterval;
                discoveryTimeout = DefaultDiscoveryTimeout;
                leaseDuration = DefaultLeaseDuration): NATConfig {....raises: [],
    tags: [], forbids: [].}
Source   Edit  

Methods

method setup(self: NATService; switch: Switch) {....raises: [ServiceSetupError],
    raises: [], tags: [RootEffect, WriteIOEffect], forbids: [].}
Source   Edit  
method start(self: NATService; switch: Switch): InternalRaisesFuture[void,
    (CancelledError,)] {....stackTrace: false, raises: [], gcsafe, raises: [],
                         tags: [RootEffect], forbids: [].}
Source   Edit  
method stop(self: NATService; switch: Switch): InternalRaisesFuture[void,
    (CancelledError,)] {....stackTrace: false, raises: [], gcsafe, raises: [],
                         tags: [RootEffect], forbids: [].}
Source   Edit