Commit graph

123 commits

Author SHA1 Message Date
Dave Collins
bcb5a21b37 Add comment to ErrBadAuth to make go lint happy. 2014-02-04 15:37:34 -06:00
Josh Rickmar
8f43dc758e Fix build. 2014-01-22 21:21:05 -05:00
Dave Collins
0d40bf901d Implement alternative auth for websockets.
The previous websocket code required HTTP auth headers to be sent in order
to use the websocket.  While this makes sense for most applications, some
use cases such as javascript-based websockets from browsers do no have the
ability to send headers.

This commit modifies the authentication logic to allow an alternative
authentication mechanism when HTTP auth headers can't be sent.  In
particular, it introduces a new JSON-RPC command named authenticate which
accepts the username and passphrase for the RPC server.  The command is
only required if the connetion has not already been authenticated via HTTP
auth headers and it must be the first command to be received.  Sending any
other command will immediately disconnect the websocket.

ok from @owainga and @jrick.

This closes #77.
2014-01-22 17:40:14 -06:00
Josh Rickmar
d3e4bcdcf5 Fix sendrawtransaction for websockets.
This fixes two issues: first, the sendrawtransaction handler had an
extra character in the key in the websocket handler map, preventing
the handler from never running.  Second, a nil pointer dereference was
removed from the handler.

This change fixes the minedtx notifications for btcwallet, since the
websocket-handler now runs instead of falling back to the legacy RPC
handler.
2014-01-20 18:27:27 -05:00
Dave Collins
8c7d44c8dc Add authentication deadline to RPC server cnxns.
Previously it was possible to open a connection to the RPC server, never
authenticate, and idle forever.

This is work toward #68.
2014-01-18 00:08:39 -06:00
Dave Collins
737e69594b Don't spend time on txout ntfns when no listeners. 2014-01-17 16:30:01 -06:00
Dave Collins
9474ef29d7 Use strings in websocket send/receive.
The websocket package assumes binary blobs if []byte is used.  Since we're
using JSON-RPC for all the websocket communications, it should be text
based.

This commit changes the websocket Send/Receive and associated channels to
strings accordingly.
2014-01-17 15:48:00 -06:00
Dave Collins
75554fab09 Fix merge conflict. 2014-01-17 15:45:23 -06:00
Dave Collins
f089853d4d Move RPC websocket init code to rpcwebsocket.go. 2014-01-17 15:44:36 -06:00
Josh Rickmar
20e56d6eda Ask for block(dis)connected updates.
This removes the last notification that was being sent unsolicited.
Since it is no longer needed, the code to duplicate notifications to
all clients has been removed.
2014-01-17 16:38:16 -05:00
Josh Rickmar
bd98836a2b Fix several bugs in the RPC server shutdown.
The RPC server was performing some of the shutdown logic in the wrong
order, that is, logging the the server has shut down, waiting for all
server goroutines to finish, and then closing a channel to notify
server goroutines to stop.  These three items have been reversed to
fix a hang where goroutines currently being waited on had not shut
down because they did not receive the notification.

While here, the server waitgroup was incremented for a goroutine that
was running without it, another select statement was added to stop a
duplicate close (which never occured last commit when I added the
select statements), and the "stopping rescan" logging was moved to
debug to make the ^C shutdown logging nicer.
2014-01-14 22:53:07 -05:00
Josh Rickmar
d8227c2751 Only close websocket disconnected chan if still open.
A channel cannot be closed multiple times, so use a select statement
to only close the channel if it can not be read from.
2014-01-14 21:47:27 -05:00
Josh Rickmar
86600a0356 Remove punctuation from end of logging for consistency. 2014-01-14 16:41:32 -05:00
Josh Rickmar
051a9013ce Stop rescans when a websocket client disconnects.
Fixes #66.
2014-01-14 15:59:31 -05:00
Josh Rickmar
6abad1d8ac Change websocket handlers to return results.
This is the first step to fixing #66.
2014-01-14 13:15:22 -05:00
Josh Rickmar
cd3084afcd Rework the btcwallet connection.
This changes the protocol between btcd and btcwallet to follow
JSON-RPC specifications sending notifications as requests with an
empty ID.

The notification request context handling has been greatly cleaned up
now that IDs no longer need to be saved when sending notifications.
2014-01-09 14:03:00 -05:00
Dave Collins
462bc5a031 Update for recent btcscript API changes.
This commit changes all code which deals with extracting addresses from
scripts to use the btcscript API ExtractPkScriptAddrs which in turn makes
use of the new btcutil.Address interface.

This provides much cleaner code for dealing with arbitrary script
destinations which is extensible without having to churn the APIs if new
destination types are added.
2014-01-08 11:22:29 -06:00
David Hill
47c92c0e62 fix typo 2014-01-06 15:57:37 -05:00
Josh Rickmar
405eca4a44 Remove usage of deprecated address encode/decode API. 2014-01-03 13:22:28 -05:00
Dave Collins
aeec39c1ff Add 2014 to copyright dates. 2014-01-01 10:16:15 -06:00
Dave Collins
835cee229a Move RPC handler maps near the top of file.
Since the command to handler mappings are the most often modified and
referenced code in rpcserver.go and rpcwebsocket.go, move them near the
top of their respective files.
2013-12-31 14:48:50 -06:00
Dave Collins
9b166b3876 Remove wallet notifications chan from std commands.
This commit cleans up the standard RPC command hanlding a bit by removing
the websocket specific notification channel from the handlers.  This was
previously required because the sendrawtransaction, when called from a
websocket enabled connection, needs to add a notification for when the
transaction is mined.

This commit modifies that to instead implement a websocket extended
version of sendrawtransaction which invokes the standard handler and adds
the notification.  In addition, the main send was modified to first look
if the command has a websocket specific handler first, and then falls back
to standard commands, rather than the previous approach of first checking
for a standard command and falling through to websocket commands.  This
essentially allows websockets connections to extend commands with the same
name with additional functionality such as what was done in this commit.
2013-12-31 14:42:15 -06:00
Dave Collins
5ad6d543d6 Move RPC websocket code to its own file.
The rpcserver.go file is starting to get a bit unwieldy.  This commit
moves the separable websocket specific bits into a separate file named
rpcwebsocket.go.
2013-12-31 13:19:07 -06:00