Skip to content

Commit

Permalink
style: fix code style with nph (#1246)
Browse files Browse the repository at this point in the history
  • Loading branch information
vladopajic authored Feb 11, 2025
1 parent 78a4344 commit 5d382b6
Show file tree
Hide file tree
Showing 15 changed files with 23 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
# 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.
run: |
VERSION="v0.5.1"
VERSION="v0.6.1"
ARCHIVE="nph-linux_x64.tar.gz"
curl -L "https://github.com/arnetheduck/nph/releases/download/${VERSION}/${ARCHIVE}" -o ${ARCHIVE}
tar -xzf ${ARCHIVE}
Expand Down
3 changes: 1 addition & 2 deletions examples/tutorial_4_gossipsub.nim
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ proc oneNode(node: Node, rng: ref HmacDrbgContext) {.async.} =
let decoded = MetricList.decode(message.data)
if decoded.isErr:
return ValidationResult.Reject
return ValidationResult.Accept
,
return ValidationResult.Accept,
)
# This "validator" will attach to the `metrics` topic and make sure
# that every message in this topic is valid. This allows us to stop
Expand Down
12 changes: 4 additions & 8 deletions examples/tutorial_6_game.nim
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,7 @@ proc networking(g: Game) {.async.} =
# We are "player 2"
swap(g.localPlayer, g.remotePlayer)
except CatchableError as exc:
discard
,
discard,
)

await switch.start()
Expand Down Expand Up @@ -268,14 +267,11 @@ nico.init("Status", "Tron")
nico.createWindow("Tron", mapSize * 4, mapSize * 4, 4, false)
nico.run(
proc() =
discard
,
discard,
proc(dt: float32) =
game.update(dt)
,
game.update(dt),
proc() =
game.draw()
,
game.draw(),
)
waitFor(netFut.cancelAndWait())

Expand Down
9 changes: 3 additions & 6 deletions libp2p/crypto/hkdf.nim
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,15 @@ proc hkdf*[T: sha256, len: static int](
if salt.len > 0:
unsafeAddr salt[0]
else:
nil
,
nil,
csize_t(salt.len),
)
hkdfInject(
ctx,
if ikm.len > 0:
unsafeAddr ikm[0]
else:
nil
,
nil,
csize_t(ikm.len),
)
hkdfFlip(ctx)
Expand All @@ -48,8 +46,7 @@ proc hkdf*[T: sha256, len: static int](
if info.len > 0:
unsafeAddr info[0]
else:
nil
,
nil,
csize_t(info.len),
addr outputs[i][0],
csize_t(outputs[i].len),
Expand Down
3 changes: 1 addition & 2 deletions libp2p/discovery/discoverymngr.nim
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ proc add*[T](pa: var PeerAttributes, value: T) =
Attribute[T](
value: value,
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),
)
)

Expand Down
6 changes: 2 additions & 4 deletions libp2p/muxers/yamux/yamux.nim
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ proc `$`(header: YamuxHeader): string =
if a != "":
a & ", " & $b
else:
$b
,
$b,
"",
) & "}, " & "streamId: " & $header.streamId & ", " & "length: " & $header.length &
"}"
Expand Down Expand Up @@ -176,8 +175,7 @@ proc `$`(channel: YamuxChannel): string =
if a != "":
a & ", " & b
else:
b
,
b,
"",
) & "}"

Expand Down
3 changes: 1 addition & 2 deletions libp2p/protocols/connectivity/autonat/server.nim
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ proc sendResponseError(
if text == "":
Opt.none(string)
else:
Opt.some(text)
,
Opt.some(text),
ma: Opt.none(MultiAddress),
).encode()
await conn.writeLp(pb.buffer)
Expand Down
3 changes: 1 addition & 2 deletions libp2p/protocols/connectivity/relay/relay.nim
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,7 @@ proc setup*(r: Relay, switch: Switch) =
r.switch = switch
r.switch.addPeerEventHandler(
proc(peerId: PeerId, event: PeerEvent) {.async.} =
r.rsvp.del(peerId)
,
r.rsvp.del(peerId),
Left,
)

Expand Down
3 changes: 1 addition & 2 deletions libp2p/protocols/protocol.nim
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ proc new*(
when maxIncomingStreams is int:
Opt.some(maxIncomingStreams)
else:
maxIncomingStreams
,
maxIncomingStreams,
)

proc new*[E](
Expand Down
3 changes: 1 addition & 2 deletions libp2p/protocols/pubsub/gossipsub/behavior.nim
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@ proc peerExchangeList*(g: GossipSub, topic: string): seq[PeerInfoMsg] =
if x.peerId in sprBook:
sprBook[x.peerId].encode().get(default(seq[byte]))
else:
default(seq[byte])
,
default(seq[byte]),
)

proc handleGraft*(
Expand Down
3 changes: 1 addition & 2 deletions libp2p/stream/bufferstream.nim
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ chronicles.formatIt(BufferStream):

proc len*(s: BufferStream): int =
s.readBuf.len + (if s.readQueue.len > 0: s.readQueue[0].len()
else: 0
)
else: 0)

method initStream*(s: BufferStream) =
if s.objName.len == 0:
Expand Down
3 changes: 1 addition & 2 deletions libp2p/transports/tcptransport.nim
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ proc new*(
if ServerFlags.TcpNoDelay in flags:
{SocketFlags.TcpNoDelay}
else:
default(set[SocketFlags])
,
default(set[SocketFlags]),
upgrader: upgrade,
networkReachability: NetworkReachability.Unknown,
connectionsTimeout: connectionsTimeout,
Expand Down
3 changes: 1 addition & 2 deletions libp2p/wire.nim
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ proc connect*(
if localAddress.isSome():
initTAddress(localAddress.expect("just checked")).tryGet()
else:
TransportAddress()
,
TransportAddress(),
flags,
)
do:
Expand Down
6 changes: 2 additions & 4 deletions tests/commoninterop.nim
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ type
SwitchCreator = proc(
ma: MultiAddress = MultiAddress.init("/ip4/127.0.0.1/tcp/0").tryGet(),
prov: TransportProvider = proc(upgr: Upgrade): Transport =
TcpTransport.new({}, upgr)
,
TcpTransport.new({}, upgr),
relay: Relay = Relay.new(circuitRelayV1 = true),
): Switch {.gcsafe, raises: [LPError].}
DaemonPeerInfo = daemonapi.PeerInfo
Expand Down Expand Up @@ -301,8 +300,7 @@ proc commonInteropTests*(name: string, swCreator: SwitchCreator) =
let nativeNode = swCreator(
ma = wsAddress,
prov = proc(upgr: Upgrade): Transport =
WsTransport.new(upgr)
,
WsTransport.new(upgr),
)

nativeNode.mount(proto)
Expand Down
6 changes: 2 additions & 4 deletions tests/testinterop.nim
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import ../libp2p/crypto/crypto, ../libp2p/protocols/connectivity/relay/[relay, c
proc switchMplexCreator(
ma: MultiAddress = MultiAddress.init("/ip4/127.0.0.1/tcp/0").tryGet(),
prov: TransportProvider = proc(upgr: Upgrade): Transport =
TcpTransport.new({}, upgr)
,
TcpTransport.new({}, upgr),
relay: Relay = Relay.new(circuitRelayV1 = true),
): Switch {.raises: [LPError].} =
SwitchBuilder
Expand All @@ -29,8 +28,7 @@ proc switchMplexCreator(
proc switchYamuxCreator(
ma: MultiAddress = MultiAddress.init("/ip4/127.0.0.1/tcp/0").tryGet(),
prov: TransportProvider = proc(upgr: Upgrade): Transport =
TcpTransport.new({}, upgr)
,
TcpTransport.new({}, upgr),
relay: Relay = Relay.new(circuitRelayV1 = true),
): Switch {.raises: [LPError].} =
SwitchBuilder
Expand Down

0 comments on commit 5d382b6

Please sign in to comment.