aboutsummaryrefslogtreecommitdiffstats
path: root/rpc
diff options
context:
space:
mode:
authorBas van Kervel <basvankervel@gmail.com>2017-06-13 17:49:07 +0800
committerBas van Kervel <basvankervel@gmail.com>2017-06-15 17:53:15 +0800
commitb58a5016738b92db19e08ec87ef34ce3250fae6b (patch)
treefa9485b3f711204b14edae5dcbc812e624490c68 /rpc
parent80f7c6c2996ad47f70a5070c400b1fd87a20c59c (diff)
downloaddexon-b58a5016738b92db19e08ec87ef34ce3250fae6b.tar
dexon-b58a5016738b92db19e08ec87ef34ce3250fae6b.tar.gz
dexon-b58a5016738b92db19e08ec87ef34ce3250fae6b.tar.bz2
dexon-b58a5016738b92db19e08ec87ef34ce3250fae6b.tar.lz
dexon-b58a5016738b92db19e08ec87ef34ce3250fae6b.tar.xz
dexon-b58a5016738b92db19e08ec87ef34ce3250fae6b.tar.zst
dexon-b58a5016738b92db19e08ec87ef34ce3250fae6b.zip
whisperv5: integrate whisper and add whisper RPC simulator
Diffstat (limited to 'rpc')
-rw-r--r--rpc/client.go46
1 files changed, 46 insertions, 0 deletions
diff --git a/rpc/client.go b/rpc/client.go
index 591986987..f02366a39 100644
--- a/rpc/client.go
+++ b/rpc/client.go
@@ -349,6 +349,52 @@ func (c *Client) BatchCallContext(ctx context.Context, b []BatchElem) error {
return err
}
+// ShhSubscribe calls the "shh_subscribe" method with the given arguments,
+// registering a subscription. Server notifications for the subscription are
+// sent to the given channel. The element type of the channel must match the
+// expected type of content returned by the subscription.
+//
+// The context argument cancels the RPC request that sets up the subscription but has no
+// effect on the subscription after ShhSubscribe has returned.
+//
+// Slow subscribers will be dropped eventually. Client buffers up to 8000 notifications
+// before considering the subscriber dead. The subscription Err channel will receive
+// ErrSubscriptionQueueOverflow. Use a sufficiently large buffer on the channel or ensure
+// that the channel usually has at least one reader to prevent this issue.
+func (c *Client) ShhSubscribe(ctx context.Context, channel interface{}, args ...interface{}) (*ClientSubscription, error) {
+ // Check type of channel first.
+ chanVal := reflect.ValueOf(channel)
+ if chanVal.Kind() != reflect.Chan || chanVal.Type().ChanDir()&reflect.SendDir == 0 {
+ panic("first argument to ShhSubscribe must be a writable channel")
+ }
+ if chanVal.IsNil() {
+ panic("channel given to ShhSubscribe must not be nil")
+ }
+ if c.isHTTP {
+ return nil, ErrNotificationsUnsupported
+ }
+
+ msg, err := c.newMessage("shh"+subscribeMethodSuffix, args...)
+ if err != nil {
+ return nil, err
+ }
+ op := &requestOp{
+ ids: []json.RawMessage{msg.ID},
+ resp: make(chan *jsonrpcMessage),
+ sub: newClientSubscription(c, "shh", chanVal),
+ }
+
+ // Send the subscription request.
+ // The arrival and validity of the response is signaled on sub.quit.
+ if err := c.send(ctx, op, msg); err != nil {
+ return nil, err
+ }
+ if _, err := op.wait(ctx); err != nil {
+ return nil, err
+ }
+ return op.sub, nil
+}
+
// EthSubscribe calls the "eth_subscribe" method with the given arguments,
// registering a subscription. Server notifications for the subscription are
// sent to the given channel. The element type of the channel must match the