mirror of
https://github.com/LBRYFoundation/lbcd.git
synced 2025-08-23 17:47:24 +00:00
Move RPC websocket init code to rpcwebsocket.go.
This commit is contained in:
parent
20e56d6eda
commit
f089853d4d
2 changed files with 14 additions and 8 deletions
10
rpcserver.go
10
rpcserver.go
|
@ -7,7 +7,6 @@ package main
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"code.google.com/p/go.net/websocket"
|
"code.google.com/p/go.net/websocket"
|
||||||
"container/list"
|
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"crypto/subtle"
|
"crypto/subtle"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
|
@ -124,7 +123,7 @@ type rpcServer struct {
|
||||||
shutdown int32
|
shutdown int32
|
||||||
server *server
|
server *server
|
||||||
authsha [sha256.Size]byte
|
authsha [sha256.Size]byte
|
||||||
ws wsContext
|
ws *wsContext
|
||||||
wg sync.WaitGroup
|
wg sync.WaitGroup
|
||||||
listeners []net.Listener
|
listeners []net.Listener
|
||||||
quit chan int
|
quit chan int
|
||||||
|
@ -240,15 +239,10 @@ func newRPCServer(listenAddrs []string, s *server) (*rpcServer, error) {
|
||||||
rpc := rpcServer{
|
rpc := rpcServer{
|
||||||
authsha: sha256.Sum256([]byte(auth)),
|
authsha: sha256.Sum256([]byte(auth)),
|
||||||
server: s,
|
server: s,
|
||||||
|
ws: newWebsocketContext(),
|
||||||
quit: make(chan int),
|
quit: make(chan int),
|
||||||
}
|
}
|
||||||
|
|
||||||
// initialize memory for websocket connections
|
|
||||||
rpc.ws.connections = make(map[ntfnChan]*requestContexts)
|
|
||||||
rpc.ws.txNotifications = make(map[string]*list.List)
|
|
||||||
rpc.ws.spentNotifications = make(map[btcwire.OutPoint]*list.List)
|
|
||||||
rpc.ws.minedTxNotifications = make(map[btcwire.ShaHash]*list.List)
|
|
||||||
|
|
||||||
// check for existence of cert file and key file
|
// check for existence of cert file and key file
|
||||||
if !fileExists(cfg.RPCKey) && !fileExists(cfg.RPCCert) {
|
if !fileExists(cfg.RPCKey) && !fileExists(cfg.RPCCert) {
|
||||||
// if both files do not exist, we generate them.
|
// if both files do not exist, we generate them.
|
||||||
|
|
|
@ -214,6 +214,18 @@ func (r *wsContext) CloseListeners(n ntfnChan) {
|
||||||
close(n)
|
close(n)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// newWebsocketContext returns a new websocket context that is used
|
||||||
|
// for handling websocket requests and notifications.
|
||||||
|
func newWebsocketContext() *wsContext {
|
||||||
|
return &wsContext{
|
||||||
|
connections: make(map[ntfnChan]*requestContexts),
|
||||||
|
walletNotificationMaster: make(ntfnChan),
|
||||||
|
txNotifications: make(map[string]*list.List),
|
||||||
|
spentNotifications: make(map[btcwire.OutPoint]*list.List),
|
||||||
|
minedTxNotifications: make(map[btcwire.ShaHash]*list.List),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// requestContexts holds all requests for a single wallet connection.
|
// requestContexts holds all requests for a single wallet connection.
|
||||||
type requestContexts struct {
|
type requestContexts struct {
|
||||||
// blockUpdates specifies whether a client has requested notifications
|
// blockUpdates specifies whether a client has requested notifications
|
||||||
|
|
Loading…
Add table
Reference in a new issue