mirror of
https://github.com/status-im/go-waku.git
synced 2025-01-15 00:04:36 +00:00
feat(c-bindings): list pubsub topics
This commit is contained in:
parent
c690b6c050
commit
bbb558e685
@ -847,6 +847,24 @@ For example:
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### `extern char* waku_relay_topics()`
|
||||||
|
|
||||||
|
Get the list of subscribed pubsub topics in Waku Relay.
|
||||||
|
|
||||||
|
**Returns**
|
||||||
|
|
||||||
|
A [`JsonResponse`](#jsonresponse-type).
|
||||||
|
If the execution is successful, the `result` field will contain an array of pubsub topics.
|
||||||
|
|
||||||
|
For example:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"result": ["pubsubTopic1", "pubsubTopic2"]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
**Events**
|
**Events**
|
||||||
|
|
||||||
When a message is received, a ``"message"` event` is emitted containing the message, pubsub topic, and node ID in which
|
When a message is received, a ``"message"` event` is emitted containing the message, pubsub topic, and node ID in which
|
||||||
|
@ -6,57 +6,72 @@ import (
|
|||||||
mobile "github.com/waku-org/go-waku/mobile"
|
mobile "github.com/waku-org/go-waku/mobile"
|
||||||
)
|
)
|
||||||
|
|
||||||
//export waku_relay_enough_peers
|
|
||||||
// Determine if there are enough peers to publish a message on a topic. Use NULL
|
// Determine if there are enough peers to publish a message on a topic. Use NULL
|
||||||
// to verify the number of peers in the default pubsub topic
|
// to verify the number of peers in the default pubsub topic
|
||||||
|
//
|
||||||
|
//export waku_relay_enough_peers
|
||||||
func waku_relay_enough_peers(topic *C.char) *C.char {
|
func waku_relay_enough_peers(topic *C.char) *C.char {
|
||||||
response := mobile.RelayEnoughPeers(C.GoString(topic))
|
response := mobile.RelayEnoughPeers(C.GoString(topic))
|
||||||
return C.CString(response)
|
return C.CString(response)
|
||||||
}
|
}
|
||||||
|
|
||||||
//export waku_relay_publish
|
|
||||||
// Publish a message using waku relay and returns the message ID. Use NULL for topic to use the default pubsub topic
|
// Publish a message using waku relay and returns the message ID. Use NULL for topic to use the default pubsub topic
|
||||||
// If ms is greater than 0, the broadcast of the message must happen before the timeout
|
// If ms is greater than 0, the broadcast of the message must happen before the timeout
|
||||||
// (in milliseconds) is reached, or an error will be returned.
|
// (in milliseconds) is reached, or an error will be returned.
|
||||||
|
//
|
||||||
|
//export waku_relay_publish
|
||||||
func waku_relay_publish(messageJSON *C.char, topic *C.char, ms C.int) *C.char {
|
func waku_relay_publish(messageJSON *C.char, topic *C.char, ms C.int) *C.char {
|
||||||
response := mobile.RelayPublish(C.GoString(messageJSON), C.GoString(topic), int(ms))
|
response := mobile.RelayPublish(C.GoString(messageJSON), C.GoString(topic), int(ms))
|
||||||
return C.CString(response)
|
return C.CString(response)
|
||||||
}
|
}
|
||||||
|
|
||||||
//export waku_relay_publish_enc_asymmetric
|
|
||||||
// Publish a message encrypted with a secp256k1 public key using waku relay and returns the message ID. Use NULL for topic to use the default pubsub topic.
|
// Publish a message encrypted with a secp256k1 public key using waku relay and returns the message ID. Use NULL for topic to use the default pubsub topic.
|
||||||
// publicKey must be a hex string prefixed with "0x" containing a valid secp256k1 public key.
|
// publicKey must be a hex string prefixed with "0x" containing a valid secp256k1 public key.
|
||||||
// optionalSigningKey is an optional hex string prefixed with "0x" containing a valid secp256k1 private key for signing the message. Use NULL otherwise
|
// optionalSigningKey is an optional hex string prefixed with "0x" containing a valid secp256k1 private key for signing the message. Use NULL otherwise
|
||||||
// If ms is greater than 0, the broadcast of the message must happen before the timeout
|
// If ms is greater than 0, the broadcast of the message must happen before the timeout
|
||||||
// (in milliseconds) is reached, or an error will be returned.
|
// (in milliseconds) is reached, or an error will be returned.
|
||||||
|
//
|
||||||
|
//export waku_relay_publish_enc_asymmetric
|
||||||
func waku_relay_publish_enc_asymmetric(messageJSON *C.char, topic *C.char, publicKey *C.char, optionalSigningKey *C.char, ms C.int) *C.char {
|
func waku_relay_publish_enc_asymmetric(messageJSON *C.char, topic *C.char, publicKey *C.char, optionalSigningKey *C.char, ms C.int) *C.char {
|
||||||
response := mobile.RelayPublishEncodeAsymmetric(C.GoString(messageJSON), C.GoString(topic), C.GoString(publicKey), C.GoString(optionalSigningKey), int(ms))
|
response := mobile.RelayPublishEncodeAsymmetric(C.GoString(messageJSON), C.GoString(topic), C.GoString(publicKey), C.GoString(optionalSigningKey), int(ms))
|
||||||
return C.CString(response)
|
return C.CString(response)
|
||||||
}
|
}
|
||||||
|
|
||||||
//export waku_relay_publish_enc_symmetric
|
|
||||||
// Publish a message encrypted with a 32 bytes symmetric key using waku relay and returns the message ID. Use NULL for topic to use the default pubsub topic.
|
// Publish a message encrypted with a 32 bytes symmetric key using waku relay and returns the message ID. Use NULL for topic to use the default pubsub topic.
|
||||||
// symmetricKey must be a hex string prefixed with "0x" containing a 32 bytes symmetric key
|
// symmetricKey must be a hex string prefixed with "0x" containing a 32 bytes symmetric key
|
||||||
// optionalSigningKey is an optional hex string prefixed with "0x" containing a valid secp256k1 private key for signing the message. Use NULL otherwise
|
// optionalSigningKey is an optional hex string prefixed with "0x" containing a valid secp256k1 private key for signing the message. Use NULL otherwise
|
||||||
// If ms is greater than 0, the broadcast of the message must happen before the timeout
|
// If ms is greater than 0, the broadcast of the message must happen before the timeout
|
||||||
// (in milliseconds) is reached, or an error will be returned.
|
// (in milliseconds) is reached, or an error will be returned.
|
||||||
|
//
|
||||||
|
//export waku_relay_publish_enc_symmetric
|
||||||
func waku_relay_publish_enc_symmetric(messageJSON *C.char, topic *C.char, symmetricKey *C.char, optionalSigningKey *C.char, ms C.int) *C.char {
|
func waku_relay_publish_enc_symmetric(messageJSON *C.char, topic *C.char, symmetricKey *C.char, optionalSigningKey *C.char, ms C.int) *C.char {
|
||||||
response := mobile.RelayPublishEncodeSymmetric(C.GoString(messageJSON), C.GoString(topic), C.GoString(symmetricKey), C.GoString(optionalSigningKey), int(ms))
|
response := mobile.RelayPublishEncodeSymmetric(C.GoString(messageJSON), C.GoString(topic), C.GoString(symmetricKey), C.GoString(optionalSigningKey), int(ms))
|
||||||
return C.CString(response)
|
return C.CString(response)
|
||||||
}
|
}
|
||||||
|
|
||||||
//export waku_relay_subscribe
|
|
||||||
// Subscribe to a WakuRelay topic. Set the topic to NULL to subscribe
|
// Subscribe to a WakuRelay topic. Set the topic to NULL to subscribe
|
||||||
// to the default topic. Returns a json response. When a message is received,
|
// to the default topic. Returns a json response. When a message is received,
|
||||||
// a "message" event is emitted containing the message and pubsub topic in which
|
// a "message" event is emitted containing the message and pubsub topic in which
|
||||||
// the message was received
|
// the message was received
|
||||||
|
//
|
||||||
|
//export waku_relay_subscribe
|
||||||
func waku_relay_subscribe(topic *C.char) *C.char {
|
func waku_relay_subscribe(topic *C.char) *C.char {
|
||||||
response := mobile.RelaySubscribe(C.GoString(topic))
|
response := mobile.RelaySubscribe(C.GoString(topic))
|
||||||
return C.CString(response)
|
return C.CString(response)
|
||||||
}
|
}
|
||||||
|
|
||||||
//export waku_relay_unsubscribe
|
// Returns a json response with the list of pubsub topics the node
|
||||||
|
// is subscribed to in WakuRelay
|
||||||
|
//
|
||||||
|
//export waku_relay_topics
|
||||||
|
func waku_relay_topics() *C.char {
|
||||||
|
response := mobile.RelayTopics()
|
||||||
|
return C.CString(response)
|
||||||
|
}
|
||||||
|
|
||||||
// Closes the pubsub subscription to a pubsub topic
|
// Closes the pubsub subscription to a pubsub topic
|
||||||
|
//
|
||||||
|
//export waku_relay_unsubscribe
|
||||||
func waku_relay_unsubscribe(topic *C.char) *C.char {
|
func waku_relay_unsubscribe(topic *C.char) *C.char {
|
||||||
response := mobile.RelayUnsubscribe(C.GoString(topic))
|
response := mobile.RelayUnsubscribe(C.GoString(topic))
|
||||||
return C.CString(response)
|
return C.CString(response)
|
||||||
|
@ -114,6 +114,14 @@ func RelaySubscribe(topic string) string {
|
|||||||
return MakeJSONResponse(relaySubscribe(topic))
|
return MakeJSONResponse(relaySubscribe(topic))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func RelayTopics() string {
|
||||||
|
if wakuState.node == nil {
|
||||||
|
return MakeJSONResponse(errWakuNodeNotReady)
|
||||||
|
}
|
||||||
|
|
||||||
|
return PrepareJSONResponse(wakuState.node.Relay().Topics(), nil)
|
||||||
|
}
|
||||||
|
|
||||||
func RelayUnsubscribe(topic string) string {
|
func RelayUnsubscribe(topic string) string {
|
||||||
if wakuState.node == nil {
|
if wakuState.node == nil {
|
||||||
return MakeJSONResponse(errWakuNodeNotReady)
|
return MakeJSONResponse(errWakuNodeNotReady)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user