style: fix code style with nph (#1246)

This commit is contained in:
vladopajic 2025-02-11 16:39:08 +01:00 committed by GitHub
parent 78a4344054
commit 5d382b6423
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
15 changed files with 23 additions and 45 deletions

View File

@ -22,7 +22,7 @@ jobs:
# Pin nph to a specific version to avoid sudden style differences. # Pin nph to a specific version to avoid sudden style differences.
# Updating nph version should be accompanied with running the new version on the fluffy directory. # Updating nph version should be accompanied with running the new version on the fluffy directory.
run: | run: |
VERSION="v0.5.1" VERSION="v0.6.1"
ARCHIVE="nph-linux_x64.tar.gz" ARCHIVE="nph-linux_x64.tar.gz"
curl -L "https://github.com/arnetheduck/nph/releases/download/${VERSION}/${ARCHIVE}" -o ${ARCHIVE} curl -L "https://github.com/arnetheduck/nph/releases/download/${VERSION}/${ARCHIVE}" -o ${ARCHIVE}
tar -xzf ${ARCHIVE} tar -xzf ${ARCHIVE}

View File

@ -79,8 +79,7 @@ proc oneNode(node: Node, rng: ref HmacDrbgContext) {.async.} =
let decoded = MetricList.decode(message.data) let decoded = MetricList.decode(message.data)
if decoded.isErr: if decoded.isErr:
return ValidationResult.Reject return ValidationResult.Reject
return ValidationResult.Accept return ValidationResult.Accept,
,
) )
# This "validator" will attach to the `metrics` topic and make sure # This "validator" will attach to the `metrics` topic and make sure
# that every message in this topic is valid. This allows us to stop # that every message in this topic is valid. This allows us to stop

View File

@ -214,8 +214,7 @@ proc networking(g: Game) {.async.} =
# We are "player 2" # We are "player 2"
swap(g.localPlayer, g.remotePlayer) swap(g.localPlayer, g.remotePlayer)
except CatchableError as exc: except CatchableError as exc:
discard discard,
,
) )
await switch.start() await switch.start()
@ -268,14 +267,11 @@ nico.init("Status", "Tron")
nico.createWindow("Tron", mapSize * 4, mapSize * 4, 4, false) nico.createWindow("Tron", mapSize * 4, mapSize * 4, 4, false)
nico.run( nico.run(
proc() = proc() =
discard discard,
,
proc(dt: float32) = proc(dt: float32) =
game.update(dt) game.update(dt),
,
proc() = proc() =
game.draw() game.draw(),
,
) )
waitFor(netFut.cancelAndWait()) waitFor(netFut.cancelAndWait())

View File

@ -28,8 +28,7 @@ proc hkdf*[T: sha256, len: static int](
if salt.len > 0: if salt.len > 0:
unsafeAddr salt[0] unsafeAddr salt[0]
else: else:
nil nil,
,
csize_t(salt.len), csize_t(salt.len),
) )
hkdfInject( hkdfInject(
@ -37,8 +36,7 @@ proc hkdf*[T: sha256, len: static int](
if ikm.len > 0: if ikm.len > 0:
unsafeAddr ikm[0] unsafeAddr ikm[0]
else: else:
nil nil,
,
csize_t(ikm.len), csize_t(ikm.len),
) )
hkdfFlip(ctx) hkdfFlip(ctx)
@ -48,8 +46,7 @@ proc hkdf*[T: sha256, len: static int](
if info.len > 0: if info.len > 0:
unsafeAddr info[0] unsafeAddr info[0]
else: else:
nil nil,
,
csize_t(info.len), csize_t(info.len),
addr outputs[i][0], addr outputs[i][0],
csize_t(outputs[i].len), csize_t(outputs[i].len),

View File

@ -38,8 +38,7 @@ proc add*[T](pa: var PeerAttributes, value: T) =
Attribute[T]( Attribute[T](
value: value, value: value,
comparator: proc(f: BaseAttr, c: BaseAttr): bool = comparator: proc(f: BaseAttr, c: BaseAttr): bool =
f.ofType(T) and c.ofType(T) and f.to(T) == c.to(T) f.ofType(T) and c.ofType(T) and f.to(T) == c.to(T),
,
) )
) )

View File

@ -82,8 +82,7 @@ proc `$`(header: YamuxHeader): string =
if a != "": if a != "":
a & ", " & $b a & ", " & $b
else: else:
$b $b,
,
"", "",
) & "}, " & "streamId: " & $header.streamId & ", " & "length: " & $header.length & ) & "}, " & "streamId: " & $header.streamId & ", " & "length: " & $header.length &
"}" "}"
@ -176,8 +175,7 @@ proc `$`(channel: YamuxChannel): string =
if a != "": if a != "":
a & ", " & b a & ", " & b
else: else:
b b,
,
"", "",
) & "}" ) & "}"

View File

@ -47,8 +47,7 @@ proc sendResponseError(
if text == "": if text == "":
Opt.none(string) Opt.none(string)
else: else:
Opt.some(text) Opt.some(text),
,
ma: Opt.none(MultiAddress), ma: Opt.none(MultiAddress),
).encode() ).encode()
await conn.writeLp(pb.buffer) await conn.writeLp(pb.buffer)

View File

@ -334,8 +334,7 @@ proc setup*(r: Relay, switch: Switch) =
r.switch = switch r.switch = switch
r.switch.addPeerEventHandler( r.switch.addPeerEventHandler(
proc(peerId: PeerId, event: PeerEvent) {.async.} = proc(peerId: PeerId, event: PeerEvent) {.async.} =
r.rsvp.del(peerId) r.rsvp.del(peerId),
,
Left, Left,
) )

View File

@ -92,8 +92,7 @@ proc new*(
when maxIncomingStreams is int: when maxIncomingStreams is int:
Opt.some(maxIncomingStreams) Opt.some(maxIncomingStreams)
else: else:
maxIncomingStreams maxIncomingStreams,
,
) )
proc new*[E]( proc new*[E](

View File

@ -126,8 +126,7 @@ proc peerExchangeList*(g: GossipSub, topic: string): seq[PeerInfoMsg] =
if x.peerId in sprBook: if x.peerId in sprBook:
sprBook[x.peerId].encode().get(default(seq[byte])) sprBook[x.peerId].encode().get(default(seq[byte]))
else: else:
default(seq[byte]) default(seq[byte]),
,
) )
proc handleGraft*( proc handleGraft*(

View File

@ -44,8 +44,7 @@ chronicles.formatIt(BufferStream):
proc len*(s: BufferStream): int = proc len*(s: BufferStream): int =
s.readBuf.len + (if s.readQueue.len > 0: s.readQueue[0].len() s.readBuf.len + (if s.readQueue.len > 0: s.readQueue[0].len()
else: 0 else: 0)
)
method initStream*(s: BufferStream) = method initStream*(s: BufferStream) =
if s.objName.len == 0: if s.objName.len == 0:

View File

@ -99,8 +99,7 @@ proc new*(
if ServerFlags.TcpNoDelay in flags: if ServerFlags.TcpNoDelay in flags:
{SocketFlags.TcpNoDelay} {SocketFlags.TcpNoDelay}
else: else:
default(set[SocketFlags]) default(set[SocketFlags]),
,
upgrader: upgrade, upgrader: upgrade,
networkReachability: NetworkReachability.Unknown, networkReachability: NetworkReachability.Unknown,
connectionsTimeout: connectionsTimeout, connectionsTimeout: connectionsTimeout,

View File

@ -86,8 +86,7 @@ proc connect*(
if localAddress.isSome(): if localAddress.isSome():
initTAddress(localAddress.expect("just checked")).tryGet() initTAddress(localAddress.expect("just checked")).tryGet()
else: else:
TransportAddress() TransportAddress(),
,
flags, flags,
) )
do: do:

View File

@ -9,8 +9,7 @@ type
SwitchCreator = proc( SwitchCreator = proc(
ma: MultiAddress = MultiAddress.init("/ip4/127.0.0.1/tcp/0").tryGet(), ma: MultiAddress = MultiAddress.init("/ip4/127.0.0.1/tcp/0").tryGet(),
prov: TransportProvider = proc(upgr: Upgrade): Transport = prov: TransportProvider = proc(upgr: Upgrade): Transport =
TcpTransport.new({}, upgr) TcpTransport.new({}, upgr),
,
relay: Relay = Relay.new(circuitRelayV1 = true), relay: Relay = Relay.new(circuitRelayV1 = true),
): Switch {.gcsafe, raises: [LPError].} ): Switch {.gcsafe, raises: [LPError].}
DaemonPeerInfo = daemonapi.PeerInfo DaemonPeerInfo = daemonapi.PeerInfo
@ -301,8 +300,7 @@ proc commonInteropTests*(name: string, swCreator: SwitchCreator) =
let nativeNode = swCreator( let nativeNode = swCreator(
ma = wsAddress, ma = wsAddress,
prov = proc(upgr: Upgrade): Transport = prov = proc(upgr: Upgrade): Transport =
WsTransport.new(upgr) WsTransport.new(upgr),
,
) )
nativeNode.mount(proto) nativeNode.mount(proto)

View File

@ -5,8 +5,7 @@ import ../libp2p/crypto/crypto, ../libp2p/protocols/connectivity/relay/[relay, c
proc switchMplexCreator( proc switchMplexCreator(
ma: MultiAddress = MultiAddress.init("/ip4/127.0.0.1/tcp/0").tryGet(), ma: MultiAddress = MultiAddress.init("/ip4/127.0.0.1/tcp/0").tryGet(),
prov: TransportProvider = proc(upgr: Upgrade): Transport = prov: TransportProvider = proc(upgr: Upgrade): Transport =
TcpTransport.new({}, upgr) TcpTransport.new({}, upgr),
,
relay: Relay = Relay.new(circuitRelayV1 = true), relay: Relay = Relay.new(circuitRelayV1 = true),
): Switch {.raises: [LPError].} = ): Switch {.raises: [LPError].} =
SwitchBuilder SwitchBuilder
@ -29,8 +28,7 @@ proc switchMplexCreator(
proc switchYamuxCreator( proc switchYamuxCreator(
ma: MultiAddress = MultiAddress.init("/ip4/127.0.0.1/tcp/0").tryGet(), ma: MultiAddress = MultiAddress.init("/ip4/127.0.0.1/tcp/0").tryGet(),
prov: TransportProvider = proc(upgr: Upgrade): Transport = prov: TransportProvider = proc(upgr: Upgrade): Transport =
TcpTransport.new({}, upgr) TcpTransport.new({}, upgr),
,
relay: Relay = Relay.new(circuitRelayV1 = true), relay: Relay = Relay.new(circuitRelayV1 = true),
): Switch {.raises: [LPError].} = ): Switch {.raises: [LPError].} =
SwitchBuilder SwitchBuilder