mirror of https://github.com/waku-org/nwaku.git
fix: code review
This commit is contained in:
parent
38729bc2c8
commit
c6f47f8aeb
|
@ -84,9 +84,10 @@ 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,
|
||||
char* publicKey,
|
||||
WakuCallBack callback,
|
||||
void* userData);
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
@ -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,
|
||||
|
|
|
@ -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]
|
||||
|
@ -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(
|
||||
|
@ -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())
|
||||
|
|
Loading…
Reference in New Issue