Commit Graph

33 Commits

Author SHA1 Message Date
Neil Booth
86f6a148b9 Separate async item processor per session
Improve daemon wait logic

Fixes #100
2017-02-19 19:01:41 +09:00
Neil Booth
33cdfa4fc8 Merge branch 'nmarley-pep8' into develop 2017-02-18 12:54:01 +09:00
Neil Booth
151da40d5b Implement peer discovery protocol
Closes #104

DEFAULT_PORTS now a coin property
A Peer object maintains peer information
Revamp LocalRPC "peers" call to show a lot more information
Have lib/jsonrpc.py take care of handling request timeouts
Save and restore peers to a file
Loosen JSON RPC rules so we work with electrum-server and beancurd which don't follow the spec.
Handle incoming server.add_peer requests
Send server.add_peer registrations if peer doesn't have us or correct ports
Verify peers at regular intervals, forget stale peers, verify new peers or those with updated ports
If connecting via one port fails, try the other
Add socks.py for SOCKS4 and SOCKS5 proxying, so Tor servers can now be reached by TCP and SSL
Put full licence boilerplate in lib/ files
Disable IRC advertising on testnet
Serve a Tor banner file if it seems like a connection came from your tor proxy (see ENVIONMENT.rst)
Retry tor proxy hourly, and peers that are about to turn stale
Report more onion peers to a connection that seems to be combing from your tor proxy
Only report good peers to server.peers.subscribe; always report self if valid
Handle peers on the wrong network robustly
Default to 127.0.0.1 rather than localhost for Python <= 3.5.2 compatibility
Put peer name in logs of connections to it
Update docs
2017-02-18 12:43:45 +09:00
Nathan Marley
a03665696c recommendations from pycodestyle (pep8 style) 2017-02-07 20:12:50 -08:00
Neil Booth
a7462a6ea3 Complete rewrite of JSON RPC infrastructure
Aim to be easier for clients to use, because to do peer
discovery we must act as a client to other servers.

Split out JSON session concept from the asyncio protocol
concept.  This makes the JSON RPC support more easily
testable and usable as a stand-alone library.

In addition, support JSON RPC v1 and v2, and auto-detection
of peer's version.
2017-01-23 23:36:02 +09:00
Neil Booth
ed0646efbf Tidy up request and notification sending 2017-01-20 20:04:56 +09:00
Neil Booth
4eed43accb Add named-argument handling as per JSON RPC 2.0
This involved a rewrite of the JSON RPC layer.
I took the opportunity to clean up the handling of requests
in general.  It should now be easy to return nice help from
the docstrings.

Closes issue #99
2017-01-12 07:59:21 +09:00
Neil Booth
5cbe878cb8 Move ServerManager to controller.py
rename Controller
2017-01-02 17:30:32 +09:00
Neil Booth
99d8cbfbf6 Permit RPC requests up to 1MB
Fixes #85

Prepare 0.9.16
2016-12-21 19:47:27 +09:00
Neil Booth
263e88ad57 Tweak request handling
Pause serving sessions whose socket buffer is full (anti-DoS)
Serve requests in batches of 8
Don't store the session in the request
RPC has priority 0; every other session at least 1
Periodically consolidate small session groups into 1
2016-12-10 18:06:13 +09:00
Neil Booth
c523064632 Improve RPC groups call
Show columns correctly for RPC sessions call
2016-12-10 08:52:23 +09:00
Neil Booth
2a461bd98c Serve sessions in a priority queue.
Add new RPC command requests.
Adjust sessions RPC command to show pending requests.
Only keep first 15 chars in version string.
Set socket timeout
Try more forceful closing of socket
Fixes #67
2016-12-09 22:06:04 +09:00
Neil Booth
e40db63beb Queue requests, which have a process method. 2016-12-08 00:29:46 +09:00
Neil Booth
4e512343be Fix other JSON bugs introduced in 0.8.5
Further clean up the JSON code.
2016-12-07 19:44:36 +09:00
Shane Moore
e17a9ee2c7 Update RPC client for JSON rework and add missing arg in json_request_text
Fixes #60
2016-12-07 00:25:43 -08:00
Neil Booth
bc9027094b Fix environment variable (bauerj) 2016-12-05 06:37:22 +09:00
Neil Booth
c9a10be5ba Introduce incoming buffer size limit
- incoming buffered network requests limited to 150,000 bytes
  which I believe is ample for a genuine client
- if exceeded, the connection is dropped
- raise outgoing data limit for RPC connections to 5 MB - expect
  sessions calls can be long and connection is implicitly trusted
- similarly raise incoming buffered data limit to 5 MB for RPC
  connections
2016-11-29 20:24:58 +09:00
Neil Booth
c08ade5861 Add session logging facility
Move session logging code to protocol.py from electrum_rpc.py
Use it for periodic logging controlled by envvar LOG_SESSIONS
For each session, track sent transaction stats and show that
per-session instead of errors
2016-11-29 08:00:54 +09:00
Neil Booth
198fe298b7 Bump timeout to 15s. Show timeout if timed out. 2016-11-26 07:14:38 +09:00
Neil Booth
42c00d32d2 Rewrite lib/jsonrpc.py to be a useful client too
Use for an improved electrumx_rpc.py, so it now handles responses spread
over several packets.  Also added a timeout of 5 seconds.

Fixes #43
2016-11-25 21:19:43 +09:00
Neil Booth
b2672a4ae5 Widen subs column 2016-11-16 19:26:16 +09:00
Neil Booth
5fffc25188 Get send and recv the right way round 2016-11-14 21:12:54 +09:00
Neil Booth
0725b54a45 Tweak RPC output 2016-11-14 19:52:02 +09:00
Neil Booth
a22a4650a5 Use json.dumps to print 2016-11-14 07:54:59 +09:00
Neil Booth
831225492e Better RPC sessions stats 2016-11-13 15:28:34 +09:00
Neil Booth
3b6ab77e47 Break out JSONRPC into own file
- improved handling of JSON 2.0 RPC protocol
- permits batched requests (not yet supported by Electrum client)
2016-11-13 13:39:37 +09:00
Neil Booth
c93f6cb920 Final cleanup 2016-11-12 21:48:34 +09:00
Neil Booth
cb7b7dd1fe Move pretty printing of sessions to client
Tweak logging
2016-11-12 21:36:49 +09:00
Neil Booth
6946863879 Add setup.py
Fix electrum_rpc.py
Rename server_main.py to electrumx_server.py
2016-11-05 18:00:03 +09:00
Neil Booth
d2ebb80fac Extend copyright notice; improve comments 2016-11-03 16:45:06 +09:00
Neil Booth
334ffdaa4f Begin work on proper server 2016-10-17 20:02:42 +09:00
Neil Booth
edc33febe8 Improve help of electrumx_rpc 2016-10-16 09:31:00 +09:00
Neil Booth
0b01026b88 Add an RPC server
And associated electrumx_rpc command
2016-10-16 08:58:53 +09:00