Skip to content

Commit

Permalink
fix: code review
Browse files Browse the repository at this point in the history
  • Loading branch information
richard-ramos committed Dec 17, 2024
1 parent 38729bc commit 8121818
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
6 changes: 3 additions & 3 deletions library/libwaku.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ int waku_relay_subscribe(void* ctx,
WakuCallBack callback,
void* userData);

int waku_relay_add_protected_topic(void* ctx,
const char* pubSubTopic,
const char* publicKey,
int waku_relay_add_protected_shard(void* ctx,
int clusterId,
int shardId,
WakuCallBack callback,
void* userData);

Expand Down
15 changes: 7 additions & 8 deletions library/libwaku.nim
Original file line number Diff line number Diff line change
Expand Up @@ -360,20 +360,16 @@ proc waku_relay_subscribe(
userData,
)

proc waku_relay_add_protected_topic(
proc waku_relay_add_protected_shard(
ctx: ptr WakuContext,
pubSubTopic: cstring,
clusterId: cint,
shardId: cint,
publicKey: cstring,
callback: WakuCallBack,
userData: pointer,
): cint {.dynlib, exportc, cdecl.} =
initializeLibrary()
checkLibwakuParams(ctx, callback, userData)

let pst = pubSubTopic.alloc()
defer:
deallocShared(pst)

let pubk = publicKey.alloc()
defer:
deallocShared(pubk)
Expand All @@ -382,7 +378,10 @@ proc waku_relay_add_protected_topic(
ctx,
RequestType.RELAY,
RelayRequest.createShared(
RelayMsgType.ADD_PROTECTED_TOPIC, PubsubTopic($pst), publicKey = $pubk
RelayMsgType.ADD_PROTECTED_SHARD,
clusterId = clusterId,
shardId = shardId,
publicKey = $pubk,
),
callback,
userData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type RelayMsgType* = enum
## to return the list of all connected peers to an specific pubsub topic
LIST_MESH_PEERS
## to return the list of only the peers that conform the mesh for a particular pubsub topic
ADD_PROTECTED_TOPIC ## Protects a pubsub topic with a public key
ADD_PROTECTED_SHARD ## Protects a shard with a public key

type ThreadSafeWakuMessage* = object
payload: SharedSeq[byte]
Expand All @@ -34,19 +34,25 @@ type RelayRequest* = object
pubsubTopic: cstring
relayEventCallback: WakuRelayHandler # not used in 'PUBLISH' requests
message: ThreadSafeWakuMessage # only used in 'PUBLISH' requests
publicKey: cstring # only used in 'ADD_PROTECTED_TOPIC' requests
clusterId: cint # only used in 'ADD_PROTECTED_SHARD' requests
shardId: cint # only used in 'ADD_PROTECTED_SHARD' requests
publicKey: cstring # only used in 'ADD_PROTECTED_SHARD' requests

proc createShared*(
T: type RelayRequest,
op: RelayMsgType,
pubsubTopic: PubsubTopic,
pubsubTopic: PubsubTopic = "",
relayEventCallback: WakuRelayHandler = nil,
m = WakuMessage(),
clusterId: cint = 0,
shardId: cint = 0,
publicKey: string = "",
): ptr type T =
var ret = createShared(T)
ret[].operation = op
ret[].pubsubTopic = pubsubTopic.alloc()
ret[].clusterId = clusterId
ret[].shardId = shardId
ret[].publicKey = publicKey.alloc()
ret[].relayEventCallback = relayEventCallback
ret[].message = ThreadSafeWakuMessage(
Expand Down Expand Up @@ -125,12 +131,14 @@ proc process*(
error "LIST_MESH_PEERS failed", error = error
return err($error)
return ok($numPeersInMesh)
of ADD_PROTECTED_TOPIC:
of ADD_PROTECTED_SHARD:
try:
let relayShard =
RelayShard(clusterId: uint16(self.clusterId), shardId: uint16(self.shardId))
let protectedShard =
ProtectedShard.parseCmdArg($self.pubsubTopic & ":" & $self.publicKey)
ProtectedShard.parseCmdArg($relayShard & ":" & $self.publicKey)
waku.node.wakuRelay.addSignedShardsValidator(
@[protectedShard], uint16(waku.node.wakuMetadata.clusterId)
@[protectedShard], uint16(self.clusterId)
)
except ValueError:
return err(getCurrentExceptionMsg())
Expand Down

0 comments on commit 8121818

Please sign in to comment.