// handleNotifyReceived implements the notifyreceived command extension for
// websocket connections.
170126
func handleNotifyReceived(wsc *wsClient, icmd interface{}) (interface{}, error) {
	cmd, ok := icmd.(*btcjson.NotifyReceivedCmd)
	if !ok {
		return nil, btcjson.ErrRPCInternal
	}

	// Decode addresses to validate input, but the strings slice is used
	// directly if these are all ok.
	err := checkAddressValidity(cmd.Addresses, wsc.server.cfg.ChainParams)
	if err != nil {
		return nil, err
	}

	wsc.server.ntfnMgr.RegisterTxOutAddressRequests(wsc, cmd.Addresses)
	return nil, nil
}
109409
func (db *DB) UpdateLastPingReceived(id ID, ip net.IP, instance time.Time) error {
	return db.storeInt64(nodeItemKey(id, ip, dbNodePing), instance.Unix())
}
77706
func (g *GoWebSocket) MessageReceive(v interface{}) error {
	return websocket.Message.Receive(g.Conn, v)
}
512876
func handleStopNotifyReceived(wsc *wsClient, icmd interface{}) (interface{}, error) {
	cmd, ok := icmd.(*btcjson.StopNotifyReceivedCmd)
	if !ok {
		return nil, btcjson.ErrRPCInternal
	}

	// Decode addresses to validate input, but the strings slice is used
	// directly if these are all ok.
	err := checkAddressValidity(cmd.Addresses, wsc.server.cfg.ChainParams)
	if err != nil {
		return nil, err
	}

	for _, addr := range cmd.Addresses {
		wsc.server.ntfnMgr.UnregisterTxOutAddressRequest(wsc, addr)
	}

	return nil, nil
}
582385
func (b *Broadcaster) Notify(instance interface{}) {
	b.listenerLock.RLock()
	listeners := b.listeners
	b.listenerLock.RUnlock()
	for _, listener := range listeners {
		listener.OnUpdate(instance)
	}
}
718073
func (e *endpoint) readyReceiveSize() (int, *tcpip.Error) {
	e.mu.RLock()
	defer e.mu.RUnlock()

	// The endpoint cannot be in listen state.
	if e.state == stateListen {
		return 0, tcpip.ErrInvalidEndpointState
	}

	e.rcvListMu.Lock()
	defer e.rcvListMu.Unlock()

	return e.rcvBufUsed, nil
}
967104
func (c Client) Notify(serviceMethod string, args interface{}) error {
	req := &rpc.Request{
		ServiceMethod: serviceMethod,
		Seq:           seqNotify,
	}
	return c.codec.WriteRequest(req, args)
}
781569
func (s *SubscriptionProvider) Notify(event interface{}) {
	s.RLock()
	defer s.RUnlock()
	for _, sub := range s.subscriptions {
		if err := sub.notify(event); err != nil {
			Log.Warnf("Failed notifying subscription (%s): %s", sub.id, err)
		}
	}
}
682172
func (t *MockSocket) AddReceivedMessage(response string) {
	t.receivedMessages <- json.RawMessage(response)
}
316131
func (ref *Consumer) notificationHandler(in <-chan *cluster.Notification) {
	ref.Debug("NotificationHandler started ...")

	for {
		select {
		case note := <-in:
			ref.Config.RecvNotificationChan <- note
		case <-ref.closeChannel:
			ref.Debug("Canceling notification handler")
			return
		}
	}
}
896823
func Notifications() echo.HandlerFunc {
	return func(c echo.Context) error {
		accessData := c.Get("accessData").(*osin.AccessData)
		if accessData == nil {
			return c.String(http.StatusInternalServerError, "Invalid authorization")
		}

		websocket.Handler(func(ws *websocket.Conn) {
			// Listen from notification sent on DB channel u<ID>
			nerdz.Db().Listen("u"+strconv.Itoa(int(accessData.UserData.(uint64))), func(payload ...string) {
				if len(payload) == 1 {
					if websocket.Message.Send(ws, payload[0]) != nil {
						return
					}
				}
			})

			// try to read from client (we dont' expect a message) to prevent websocket closing
			for {
				var m string
				if websocket.Message.Receive(ws, &m) != nil {
					// If here, client closed the connection
					break
				}
			}
		}).ServeHTTP(c.Response(), c.Request())
		return nil
	}
}
1096423
func (m *scopedManager) CloseNotify() <-chan bool {
	if w, ok := m.ResponseWriter.(http.CloseNotifier); ok {
		return w.CloseNotify()
	}
	return nil
}
496001
func (c *Characteristic) HandleNotifyFunc(f func(r Request, n Notifier)) {
	c.HandleNotify(NotifyHandlerFunc(f))
}
1107899
func NewNotifyCtlHandler(xp rpc.Transporter, id libkb.ConnectionID, g *libkb.GlobalContext) *NotifyCtlHandler {
	return &NotifyCtlHandler{
		Contextified: libkb.NewContextified(g),
		BaseHandler:  NewBaseHandler(g, xp),
		id:           id,
	}
}
1065585
func NewReceived(numBlock NumBlock, numChaincode NumChaincode) Received {
	return Received{NumBlock: numBlock, NumChaincode: numChaincode}
}
75476
func (c *Client) messageHandler() {
	for {
		if c.scanner.Scan() {
			line := c.scanner.Text()
			if line == "error id=0 msg=ok" {
				c.err <- nil
			} else if matches := respTrailerRe.FindStringSubmatch(line); len(matches) == 4 {
				c.err <- NewError(matches)
			} else if strings.Index(line, "notify") == 0 {
				if n, err := decodeNotification(line); err == nil {
					// non-blocking write
					select {
					case c.notify <- n:
					default:
					}
				}
			} else {
				c.res = append(c.res, line)
			}
		} else {
			err := c.scanErr()
			c.err <- err
			if err == io.ErrUnexpectedEOF {
				close(c.disconnect)
				return
			}
		}
	}
}
1223016
func (b *Backend) SetStateReceived(signature *tasks.Signature) error {
	taskState := tasks.NewReceivedTaskState(signature)
	b.mergeNewTaskState(taskState)
	return b.updateState(taskState)
}