mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-01-04 06:53:12 +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,
|
WakuCallBack callback,
|
||||||
void* userData);
|
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,
|
int waku_relay_unsubscribe(void* ctx,
|
||||||
const char* pubSubTopic,
|
const char* pubSubTopic,
|
||||||
WakuCallBack callback,
|
WakuCallBack callback,
|
||||||
|
|||||||
@ -386,6 +386,33 @@ proc waku_relay_subscribe(
|
|||||||
userData,
|
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(
|
proc waku_relay_unsubscribe(
|
||||||
ctx: ptr WakuContext,
|
ctx: ptr WakuContext,
|
||||||
pubSubTopic: cstring,
|
pubSubTopic: cstring,
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import std/net
|
|||||||
import chronicles, chronos, stew/byteutils, results
|
import chronicles, chronos, stew/byteutils, results
|
||||||
import
|
import
|
||||||
../../../../../waku/waku_core/message/message,
|
../../../../../waku/waku_core/message/message,
|
||||||
../../../../../waku/factory/waku,
|
../../../../../waku/factory/[external_config, validator_signed, waku],
|
||||||
../../../../../waku/waku_core/message,
|
../../../../../waku/waku_core/message,
|
||||||
../../../../../waku/waku_core/time, # Timestamp
|
../../../../../waku/waku_core/time, # Timestamp
|
||||||
../../../../../waku/waku_core/topics/pubsub_topic,
|
../../../../../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
|
## to return the list of all connected peers to an specific pubsub topic
|
||||||
LIST_MESH_PEERS
|
LIST_MESH_PEERS
|
||||||
## to return the list of only the peers that conform the mesh for a particular pubsub topic
|
## 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
|
type ThreadSafeWakuMessage* = object
|
||||||
payload: SharedSeq[byte]
|
payload: SharedSeq[byte]
|
||||||
@ -33,17 +34,26 @@ type RelayRequest* = object
|
|||||||
pubsubTopic: cstring
|
pubsubTopic: cstring
|
||||||
relayEventCallback: WakuRelayHandler # not used in 'PUBLISH' requests
|
relayEventCallback: WakuRelayHandler # not used in 'PUBLISH' requests
|
||||||
message: ThreadSafeWakuMessage # only 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*(
|
proc createShared*(
|
||||||
T: type RelayRequest,
|
T: type RelayRequest,
|
||||||
op: RelayMsgType,
|
op: RelayMsgType,
|
||||||
pubsubTopic: PubsubTopic,
|
pubsubTopic: PubsubTopic = "",
|
||||||
relayEventCallback: WakuRelayHandler = nil,
|
relayEventCallback: WakuRelayHandler = nil,
|
||||||
m = WakuMessage(),
|
m = WakuMessage(),
|
||||||
|
clusterId: cint = 0,
|
||||||
|
shardId: cint = 0,
|
||||||
|
publicKey: string = "",
|
||||||
): ptr type T =
|
): ptr type T =
|
||||||
var ret = createShared(T)
|
var ret = createShared(T)
|
||||||
ret[].operation = op
|
ret[].operation = op
|
||||||
ret[].pubsubTopic = pubsubTopic.alloc()
|
ret[].pubsubTopic = pubsubTopic.alloc()
|
||||||
|
ret[].clusterId = clusterId
|
||||||
|
ret[].shardId = shardId
|
||||||
|
ret[].publicKey = publicKey.alloc()
|
||||||
ret[].relayEventCallback = relayEventCallback
|
ret[].relayEventCallback = relayEventCallback
|
||||||
ret[].message = ThreadSafeWakuMessage(
|
ret[].message = ThreadSafeWakuMessage(
|
||||||
payload: allocSharedSeq(m.payload),
|
payload: allocSharedSeq(m.payload),
|
||||||
@ -64,7 +74,8 @@ proc destroyShared(self: ptr RelayRequest) =
|
|||||||
deallocSharedSeq(self[].message.meta)
|
deallocSharedSeq(self[].message.meta)
|
||||||
when defined(rln):
|
when defined(rln):
|
||||||
deallocSharedSeq(self[].message.proof)
|
deallocSharedSeq(self[].message.proof)
|
||||||
|
deallocShared(self[].pubsubTopic)
|
||||||
|
deallocShared(self[].publicKey)
|
||||||
deallocShared(self)
|
deallocShared(self)
|
||||||
|
|
||||||
proc toWakuMessage(m: ThreadSafeWakuMessage): WakuMessage =
|
proc toWakuMessage(m: ThreadSafeWakuMessage): WakuMessage =
|
||||||
@ -120,5 +131,15 @@ proc process*(
|
|||||||
error "LIST_MESH_PEERS failed", error = error
|
error "LIST_MESH_PEERS failed", error = error
|
||||||
return err($error)
|
return err($error)
|
||||||
return ok($numPeersInMesh)
|
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("")
|
return ok("")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user