rpc/server: add notification subscription
Note that the protocol differs a bit from #895 in its notifications format, to avoid additional server-side processing we're omitting some metadata like: * block size and confirmations * transaction fees, confirmations, block hash and timestamp * application execution doesn't have ScriptHash populated Some block fields may also differ in encoding compared to `getblock` results (like nonce field). I think these differences are unnoticieable for most use cases, so we can leave them as is, but it can be changed in the future.
This commit is contained in:
parent
29ada4ca46
commit
e1408b6525
7 changed files with 688 additions and 24 deletions
35
pkg/rpc/server/subscription.go
Normal file
35
pkg/rpc/server/subscription.go
Normal file
|
@ -0,0 +1,35 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"github.com/gorilla/websocket"
|
||||
"github.com/nspcc-dev/neo-go/pkg/rpc/response"
|
||||
)
|
||||
|
||||
type (
|
||||
// subscriber is an event subscriber.
|
||||
subscriber struct {
|
||||
writer chan<- *websocket.PreparedMessage
|
||||
ws *websocket.Conn
|
||||
|
||||
// These work like slots as there is not a lot of them (it's
|
||||
// cheaper doing it this way rather than creating a map),
|
||||
// pointing to EventID is an obvious overkill at the moment, but
|
||||
// that's not for long.
|
||||
feeds [maxFeeds]response.EventID
|
||||
}
|
||||
)
|
||||
|
||||
const (
|
||||
// Maximum number of subscriptions per one client.
|
||||
maxFeeds = 16
|
||||
|
||||
// This sets notification messages buffer depth, it may seem to be quite
|
||||
// big, but there is a big gap in speed between internal event processing
|
||||
// and networking communication that is combined with spiky nature of our
|
||||
// event generation process, which leads to lots of events generated in
|
||||
// short time and they will put some pressure to this buffer (consider
|
||||
// ~500 invocation txs in one block with some notifications). At the same
|
||||
// time this channel is about sending pointers, so it's doesn't cost
|
||||
// a lot in terms of memory used.
|
||||
notificationBufSize = 1024
|
||||
)
|
Loading…
Add table
Add a link
Reference in a new issue