mirror of
https://github.com/codex-storage/nim-libp2p.git
synced 2025-01-24 17:59:05 +00:00
split switch and services decls
This commit is contained in:
parent
a1eb53b181
commit
60337320e3
@ -34,7 +34,7 @@ proc runTest(filename: string, verify: bool = true, sign: bool = true,
|
||||
rmFile "tests/" & filename.toExe
|
||||
|
||||
proc buildSample(filename: string, run = false, extraFlags = "") =
|
||||
var excstr = "nim c --opt:speed --threads:on -d:debug --verbosity:0 --hints:off -p:. " & extraFlags
|
||||
var excstr = "nim c --skipParentCfg --opt:speed --threads:on -d:debug --verbosity:0 --hints:off -p:. " & extraFlags
|
||||
excstr.add(" examples/" & filename)
|
||||
exec excstr
|
||||
if run:
|
||||
|
@ -15,6 +15,7 @@ else:
|
||||
import std/[options, deques, sequtils]
|
||||
import chronos, metrics
|
||||
import ../../../switch
|
||||
import ../../../services/service
|
||||
import ../../../wire
|
||||
import client
|
||||
from core import NetworkReachability, AutonatUnreachableError
|
||||
|
@ -16,6 +16,8 @@ import chronos, chronicles, times, tables, sequtils, options
|
||||
import ../switch,
|
||||
../protocols/connectivity/relay/[client, utils]
|
||||
|
||||
import ./service
|
||||
|
||||
logScope:
|
||||
topics = "libp2p autorelay"
|
||||
|
||||
|
@ -24,6 +24,7 @@ import ../protocols/connectivity/relay/relay
|
||||
import ../protocols/connectivity/autonat/service
|
||||
import ../protocols/connectivity/dcutr/[client, server]
|
||||
|
||||
import ./service
|
||||
|
||||
logScope:
|
||||
topics = "libp2p hpservice"
|
||||
|
29
libp2p/services/service.nim
Normal file
29
libp2p/services/service.nim
Normal file
@ -0,0 +1,29 @@
|
||||
# Nim-LibP2P
|
||||
# Copyright (c) 2023 Status Research & Development GmbH
|
||||
# Licensed under either of
|
||||
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||
# at your option.
|
||||
# This file may not be copied, modified, or distributed except according to
|
||||
# those terms.
|
||||
|
||||
import chronos, chronicles
|
||||
|
||||
import ../types
|
||||
|
||||
method setup*(self: Service, switch: Switch): Future[bool] {.base, async, gcsafe.} =
|
||||
if self.inUse:
|
||||
warn "service setup has already been called"
|
||||
return false
|
||||
self.inUse = true
|
||||
return true
|
||||
|
||||
method run*(self: Service, switch: Switch) {.base, async, gcsafe.} =
|
||||
doAssert(false, "Not implemented!")
|
||||
|
||||
method stop*(self: Service, switch: Switch): Future[bool] {.base, async, gcsafe.} =
|
||||
if not self.inUse:
|
||||
warn "service is already stopped"
|
||||
return false
|
||||
self.inUse = false
|
||||
return true
|
@ -45,9 +45,11 @@ import stream/connection,
|
||||
peerstore,
|
||||
errors,
|
||||
utility,
|
||||
dialer
|
||||
dialer,
|
||||
services/service,
|
||||
types
|
||||
|
||||
export connmanager, upgrade, dialer, peerstore
|
||||
export connmanager, upgrade, dialer, peerstore, types
|
||||
|
||||
logScope:
|
||||
topics = "libp2p switch"
|
||||
@ -61,40 +63,6 @@ logScope:
|
||||
const
|
||||
ConcurrentUpgrades* = 4
|
||||
|
||||
type
|
||||
Switch* {.public.} = ref object of Dial
|
||||
peerInfo*: PeerInfo
|
||||
connManager*: ConnManager
|
||||
transports*: seq[Transport]
|
||||
ms*: MultistreamSelect
|
||||
acceptFuts: seq[Future[void]]
|
||||
dialer*: Dial
|
||||
peerStore*: PeerStore
|
||||
nameResolver*: NameResolver
|
||||
started: bool
|
||||
services*: seq[Service]
|
||||
|
||||
Service* = ref object of RootObj
|
||||
inUse: bool
|
||||
|
||||
|
||||
method setup*(self: Service, switch: Switch): Future[bool] {.base, async, gcsafe.} =
|
||||
if self.inUse:
|
||||
warn "service setup has already been called"
|
||||
return false
|
||||
self.inUse = true
|
||||
return true
|
||||
|
||||
method run*(self: Service, switch: Switch) {.base, async, gcsafe.} =
|
||||
doAssert(false, "Not implemented!")
|
||||
|
||||
method stop*(self: Service, switch: Switch): Future[bool] {.base, async, gcsafe.} =
|
||||
if not self.inUse:
|
||||
warn "service is already stopped"
|
||||
return false
|
||||
self.inUse = false
|
||||
return true
|
||||
|
||||
proc addConnEventHandler*(s: Switch,
|
||||
handler: ConnEventHandler,
|
||||
kind: ConnEventKind) {.public.} =
|
||||
|
45
libp2p/types.nim
Normal file
45
libp2p/types.nim
Normal file
@ -0,0 +1,45 @@
|
||||
# Nim-LibP2P
|
||||
# Copyright (c) 2023 Status Research & Development GmbH
|
||||
# Licensed under either of
|
||||
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||
# at your option.
|
||||
# This file may not be copied, modified, or distributed except according to
|
||||
# those terms.
|
||||
|
||||
import chronos
|
||||
|
||||
import stream/connection,
|
||||
transports/transport,
|
||||
upgrademngrs/[upgrade, muxedupgrade],
|
||||
multistream,
|
||||
multiaddress,
|
||||
protocols/protocol,
|
||||
protocols/secure/secure,
|
||||
peerinfo,
|
||||
protocols/identify,
|
||||
muxers/muxer,
|
||||
utils/semaphore,
|
||||
connmanager,
|
||||
nameresolving/nameresolver,
|
||||
peerid,
|
||||
peerstore,
|
||||
errors,
|
||||
utility,
|
||||
dialer
|
||||
|
||||
type
|
||||
Service* = ref object of RootObj
|
||||
inUse*: bool
|
||||
|
||||
Switch* {.public.} = ref object of Dial
|
||||
peerInfo*: PeerInfo
|
||||
connManager*: ConnManager
|
||||
transports*: seq[Transport]
|
||||
ms*: MultistreamSelect
|
||||
acceptFuts*: seq[Future[void]]
|
||||
dialer*: Dial
|
||||
peerStore*: PeerStore
|
||||
nameResolver*: NameResolver
|
||||
started*: bool
|
||||
services*: seq[Service]
|
Loading…
x
Reference in New Issue
Block a user