mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-01-02 14:03:06 +00:00
feat(libwaku): add protected topic (#3211)
This commit is contained in:
parent
569060b190
commit
ba1870d114
@ -84,6 +84,13 @@ int waku_relay_subscribe(void* ctx,
|
||||
WakuCallBack callback,
|
||||
void* userData);
|
||||
|
||||
int waku_relay_add_protected_shard(void* ctx,
|
||||
int clusterId,
|
||||
int shardId,
|
||||
char* publicKey,
|
||||
WakuCallBack callback,
|
||||
void* userData);
|
||||
|
||||
int waku_relay_unsubscribe(void* ctx,
|
||||
const char* pubSubTopic,
|
||||
WakuCallBack callback,
|
||||
|
||||
@ -386,6 +386,33 @@ proc waku_relay_subscribe(
|
||||
userData,
|
||||
)
|
||||
|
||||
proc waku_relay_add_protected_shard(
|
||||
ctx: ptr WakuContext,
|
||||
clusterId: cint,
|
||||
shardId: cint,
|
||||
publicKey: cstring,
|
||||
callback: WakuCallBack,
|
||||
userData: pointer,
|
||||
): cint {.dynlib, exportc, cdecl.} =
|
||||
initializeLibrary()
|
||||
checkLibwakuParams(ctx, callback, userData)
|
||||
let pubk = publicKey.alloc()
|
||||
defer:
|
||||
deallocShared(pubk)
|
||||
|
||||
handleRequest(
|
||||
ctx,
|
||||
RequestType.RELAY,
|
||||
RelayRequest.createShared(
|
||||
RelayMsgType.ADD_PROTECTED_SHARD,
|
||||
clusterId = clusterId,
|
||||
shardId = shardId,
|
||||
publicKey = $pubk,
|
||||
),
|
||||
callback,
|
||||
userData,
|
||||
)
|
||||
|
||||
proc waku_relay_unsubscribe(
|
||||
ctx: ptr WakuContext,
|
||||
pubSubTopic: cstring,
|
||||
|
||||
@ -2,7 +2,7 @@ import std/net
|
||||
import chronicles, chronos, stew/byteutils, results
|
||||
import
|
||||
../../../../../waku/waku_core/message/message,
|
||||
../../../../../waku/factory/waku,
|
||||
../../../../../waku/factory/[external_config, validator_signed, waku],
|
||||
../../../../../waku/waku_core/message,
|
||||
../../../../../waku/waku_core/time, # Timestamp
|
||||
../../../../../waku/waku_core/topics/pubsub_topic,
|
||||
@ -17,6 +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_SHARD ## Protects a shard with a public key
|
||||
|
||||
type ThreadSafeWakuMessage* = object
|
||||
payload: SharedSeq[byte]
|
||||
@ -33,17 +34,26 @@ type RelayRequest* = object
|
||||
pubsubTopic: cstring
|
||||
relayEventCallback: WakuRelayHandler # not used in 'PUBLISH' requests
|
||||
message: ThreadSafeWakuMessage # only used in 'PUBLISH' 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(
|
||||
payload: allocSharedSeq(m.payload),
|
||||
@ -64,7 +74,8 @@ proc destroyShared(self: ptr RelayRequest) =
|
||||
deallocSharedSeq(self[].message.meta)
|
||||
when defined(rln):
|
||||
deallocSharedSeq(self[].message.proof)
|
||||
|
||||
deallocShared(self[].pubsubTopic)
|
||||
deallocShared(self[].publicKey)
|
||||
deallocShared(self)
|
||||
|
||||
proc toWakuMessage(m: ThreadSafeWakuMessage): WakuMessage =
|
||||
@ -120,5 +131,15 @@ proc process*(
|
||||
error "LIST_MESH_PEERS failed", error = error
|
||||
return err($error)
|
||||
return ok($numPeersInMesh)
|
||||
|
||||
of ADD_PROTECTED_SHARD:
|
||||
try:
|
||||
let relayShard =
|
||||
RelayShard(clusterId: uint16(self.clusterId), shardId: uint16(self.shardId))
|
||||
let protectedShard =
|
||||
ProtectedShard.parseCmdArg($relayShard & ":" & $self.publicKey)
|
||||
waku.node.wakuRelay.addSignedShardsValidator(
|
||||
@[protectedShard], uint16(self.clusterId)
|
||||
)
|
||||
except ValueError:
|
||||
return err("ADD_PROTECTED_SHARD exception: " & getCurrentExceptionMsg())
|
||||
return ok("")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user