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 (
|
||||
"bytes"
|
||||
"code.google.com/p/go.net/websocket"
|
||||
"container/list"
|
||||
"crypto/sha256"
|
||||
"crypto/subtle"
|
||||
"crypto/tls"
|
||||
|
@ -124,7 +123,7 @@ type rpcServer struct {
|
|||
shutdown int32
|
||||
server *server
|
||||
authsha [sha256.Size]byte
|
||||
ws wsContext
|
||||
ws *wsContext
|
||||
wg sync.WaitGroup
|
||||
listeners []net.Listener
|
||||
quit chan int
|
||||
|
@ -240,15 +239,10 @@ func newRPCServer(listenAddrs []string, s *server) (*rpcServer, error) {
|
|||
rpc := rpcServer{
|
||||
authsha: sha256.Sum256([]byte(auth)),
|
||||
server: s,
|
||||
ws: newWebsocketContext(),
|
||||
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
|
||||
if !fileExists(cfg.RPCKey) && !fileExists(cfg.RPCCert) {
|
||||
// if both files do not exist, we generate them.
|
||||
|
|
|
@ -214,6 +214,18 @@ func (r *wsContext) CloseListeners(n ntfnChan) {
|
|||
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.
|
||||
type requestContexts struct {
|
||||
// blockUpdates specifies whether a client has requested notifications
|
||||
|
|
Loading…
Reference in a new issue