PeerEvents creates an RPC subscription which receives peer events from the node's p2p.Server
(ctx context.Context)
| 65 | // PeerEvents creates an RPC subscription which receives peer events from the |
| 66 | // node's p2p.Server |
| 67 | func (api *PrivateAdminAPI) PeerEvents(ctx context.Context) (*rpc.Subscription, error) { |
| 68 | // Make sure the server is running, fail otherwise |
| 69 | server := api.node.Server() |
| 70 | if server == nil { |
| 71 | return nil, ErrNodeStopped |
| 72 | } |
| 73 | |
| 74 | // Create the subscription |
| 75 | notifier, supported := rpc.NotifierFromContext(ctx) |
| 76 | if !supported { |
| 77 | return nil, rpc.ErrNotificationsUnsupported |
| 78 | } |
| 79 | rpcSub := notifier.CreateSubscription() |
| 80 | |
| 81 | go func() { |
| 82 | events := make(chan *p2p.PeerEvent) |
| 83 | sub := server.SubscribeEvents(events) |
| 84 | defer sub.Unsubscribe() |
| 85 | |
| 86 | for { |
| 87 | select { |
| 88 | case event := <-events: |
| 89 | notifier.Notify(rpcSub.ID, event) |
| 90 | case <-sub.Err(): |
| 91 | return |
| 92 | case <-rpcSub.Err(): |
| 93 | return |
| 94 | case <-notifier.Closed(): |
| 95 | return |
| 96 | } |
| 97 | } |
| 98 | }() |
| 99 | |
| 100 | return rpcSub, nil |
| 101 | } |
| 102 | |
| 103 | // StartRPC starts the HTTP RPC API server. |
| 104 | func (api *PrivateAdminAPI) StartRPC(host *string, port *int, cors *string, apis *string, vhosts *string) (bool, error) { |
nothing calls this directly
no test coverage detected