diff --git a/rpcserver.go b/rpcserver.go index d9a6db52..07135ed8 100644 --- a/rpcserver.go +++ b/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. diff --git a/rpcwebsocket.go b/rpcwebsocket.go index 76d5a664..a3d6a922 100644 --- a/rpcwebsocket.go +++ b/rpcwebsocket.go @@ -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