mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-05-05 18:09:26 +00:00
add mixify option to lightpush publish
This commit is contained in:
parent
6bced60d3b
commit
08499cc329
@ -27,7 +27,8 @@ import
|
|||||||
mix/mix_protocol,
|
mix/mix_protocol,
|
||||||
mix/curve25519,
|
mix/curve25519,
|
||||||
mix/protocol,
|
mix/protocol,
|
||||||
mix/mix_metrics
|
mix/mix_metrics,
|
||||||
|
mix/entry_connection
|
||||||
|
|
||||||
import
|
import
|
||||||
../waku_core,
|
../waku_core,
|
||||||
@ -1182,17 +1183,36 @@ proc lightpushPublishHandler(
|
|||||||
pubsubTopic: PubsubTopic,
|
pubsubTopic: PubsubTopic,
|
||||||
message: WakuMessage,
|
message: WakuMessage,
|
||||||
peer: RemotePeerInfo | PeerInfo,
|
peer: RemotePeerInfo | PeerInfo,
|
||||||
|
mixify: bool = false,
|
||||||
): Future[lightpush_protocol.WakuLightPushResult] {.async.} =
|
): Future[lightpush_protocol.WakuLightPushResult] {.async.} =
|
||||||
let msgHash = pubsubTopic.computeMessageHash(message).to0xHex()
|
let msgHash = pubsubTopic.computeMessageHash(message).to0xHex()
|
||||||
|
|
||||||
if not node.wakuLightpushClient.isNil():
|
if not node.wakuLightpushClient.isNil():
|
||||||
notice "publishing message with lightpush",
|
notice "publishing message with lightpush",
|
||||||
pubsubTopic = pubsubTopic,
|
pubsubTopic = pubsubTopic,
|
||||||
contentTopic = message.contentTopic,
|
contentTopic = message.contentTopic,
|
||||||
target_peer_id = peer.peerId,
|
target_peer_id = peer.peerId,
|
||||||
msg_hash = msgHash
|
msg_hash = msgHash,
|
||||||
return await node.wakuLightpushClient.publish(some(pubsubTopic), message, peer)
|
mixify = mixify
|
||||||
|
if mixify:
|
||||||
|
let conn = MixEntryConnection.newConn(
|
||||||
|
$peer.addrs[0], #TODO: How to handle multiple addresses?
|
||||||
|
peer.peerId,
|
||||||
|
ProtocolType.fromString(WakuLightPushCodec),
|
||||||
|
node.mix,
|
||||||
|
)
|
||||||
|
return await node.wakuLightpushClient.publishWithConn(
|
||||||
|
pubsubTopic, message, conn, peer.peerId
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
return await node.wakuLightpushClient.publish(some(pubsubTopic), message, peer)
|
||||||
|
|
||||||
if not node.wakuLightPush.isNil():
|
if not node.wakuLightPush.isNil():
|
||||||
|
if mixify:
|
||||||
|
error "mixify is not supported with self hosted lightpush"
|
||||||
|
return lighpushErrorResult(
|
||||||
|
SERVICE_NOT_AVAILABLE, "Waku lightpush with mix not available"
|
||||||
|
)
|
||||||
notice "publishing message with self hosted lightpush",
|
notice "publishing message with self hosted lightpush",
|
||||||
pubsubTopic = pubsubTopic,
|
pubsubTopic = pubsubTopic,
|
||||||
contentTopic = message.contentTopic,
|
contentTopic = message.contentTopic,
|
||||||
@ -1206,11 +1226,16 @@ proc lightpushPublish*(
|
|||||||
pubsubTopic: Option[PubsubTopic],
|
pubsubTopic: Option[PubsubTopic],
|
||||||
message: WakuMessage,
|
message: WakuMessage,
|
||||||
peerOpt: Option[RemotePeerInfo] = none(RemotePeerInfo),
|
peerOpt: Option[RemotePeerInfo] = none(RemotePeerInfo),
|
||||||
|
mixify: bool = false,
|
||||||
): Future[lightpush_protocol.WakuLightPushResult] {.async.} =
|
): Future[lightpush_protocol.WakuLightPushResult] {.async.} =
|
||||||
if node.wakuLightpushClient.isNil() and node.wakuLightPush.isNil():
|
if node.wakuLightpushClient.isNil() and node.wakuLightPush.isNil():
|
||||||
error "failed to publish message as lightpush not available"
|
error "failed to publish message as lightpush not available"
|
||||||
return lighpushErrorResult(SERVICE_NOT_AVAILABLE, "Waku lightpush not available")
|
return lighpushErrorResult(SERVICE_NOT_AVAILABLE, "Waku lightpush not available")
|
||||||
|
if mixify and node.mix.isNil():
|
||||||
|
error "failed to publish message using mix as mix protocol is not mounted"
|
||||||
|
return lighpushErrorResult(
|
||||||
|
SERVICE_NOT_AVAILABLE, "Waku lightpush with mix not available"
|
||||||
|
)
|
||||||
let toPeer: RemotePeerInfo = peerOpt.valueOr:
|
let toPeer: RemotePeerInfo = peerOpt.valueOr:
|
||||||
if not node.wakuLightPush.isNil():
|
if not node.wakuLightPush.isNil():
|
||||||
RemotePeerInfo.init(node.peerId())
|
RemotePeerInfo.init(node.peerId())
|
||||||
@ -1233,7 +1258,7 @@ proc lightpushPublish*(
|
|||||||
error "lightpush publish error", error = msg
|
error "lightpush publish error", error = msg
|
||||||
return lighpushErrorResult(INTERNAL_SERVER_ERROR, msg)
|
return lighpushErrorResult(INTERNAL_SERVER_ERROR, msg)
|
||||||
|
|
||||||
return await lightpushPublishHandler(node, pubsubForPublish, message, toPeer)
|
return await lightpushPublishHandler(node, pubsubForPublish, message, toPeer, mixify)
|
||||||
|
|
||||||
## Waku RLN Relay
|
## Waku RLN Relay
|
||||||
proc mountRlnRelay*(
|
proc mountRlnRelay*(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user