Commit Graph

327 Commits

Author SHA1 Message Date
ThomasV 9c2d12923a fix: interface.close 2017-02-28 11:25:05 +01:00
Johann Bauer 9318b410bd Allow using a SOCKS5 proxy with authentication 2017-02-23 22:35:41 +01:00
Johann Bauer 2c7ab64e83 Always include default servers in the server list 2017-02-17 15:41:50 +01:00
ThomasV 3a64ec0f2e Initial segwit support (testnet only) 2017-01-25 21:42:15 +01:00
ThomasV 29e2570d3d prevent busy looping 2017-01-09 16:36:05 +01:00
ThomasV a2e7fc32ef Add fee slider class with network callback. 2017-01-09 12:36:15 +01:00
ThomasV 1358bebd37 network: do not wait for headers file on startup 2017-01-07 23:44:06 +01:00
ThomasV d042d6e970 initial testnet support (petrkr) 2017-01-07 16:58:59 +01:00
ThomasV 9138cf3cb8 remove deprecated protocols from DEFAULT_PORTS 2017-01-07 15:59:09 +01:00
Eagle[TM] a5dad77675 Update default servers 2016-12-26 23:07:52 +01:00
ThomasV 8249f5ab67 init_headers in daemon thread, and fix #1996 2016-10-24 14:57:02 +02:00
Eagle[TM] 7933448ec7 network: Update default server list 2016-09-04 14:36:11 +02:00
ThomasV b6393cbdf2 display 'low fee' in tx dialog 2016-06-15 13:31:24 +02:00
ThomasV f2d2d61894 add expected confirmation time to tx dialog 2016-06-07 17:12:31 +02:00
ThomasV bbe7b277d2 call jnius.detach on thread stop 2016-06-04 12:59:01 +02:00
ThomasV 2cf4795250 dynamic fees: define fee levels using expected confirmation times 2016-05-31 20:26:09 +02:00
ThomasV 753a28b452 set timeout to 30s for synchronous operations 2016-03-20 13:25:24 +01:00
ThomasV af780e7519 Default auto_connect to True. In Qt, the question is asked by the wizard 2016-03-08 10:00:47 +01:00
ThomasV 54df0b2845 follow up previous commit 2016-02-25 08:59:02 +01:00
ThomasV 96f144eb03 make sure the broadcast tx thread always times out 2016-02-25 08:55:06 +01:00
ThomasV 305843999e Relicensing 2016-02-24 10:20:30 +01:00
ThomasV bd5effb1b8 follow up 6f72fa4 2016-02-21 17:46:56 +01:00
ThomasV 6f72fa4e94 try to fix issue #1682 2016-02-21 17:42:33 +01:00
ThomasV 04c7d2b455 add 'donate to server' menu item 2016-02-15 16:17:07 +01:00
ThomasV 4dd479cf59 server_is_lagging: return True if no height 2016-02-15 15:58:08 +01:00
Neil Booth 371f8d6dc3 network: gracefully handle EINTR in select syscall 2016-01-16 21:14:14 +09:00
ThomasV da8fce1914 if available, use relayfee from server instead of hard coded value 2016-01-14 16:06:22 +01:00
Eagle[TM] 2c797cd75b Update default server list 2015-12-30 14:47:40 +01:00
ThomasV 9ec4cbeed1 fix issue #1572 2015-12-06 13:32:50 +01:00
ThomasV 74a9e2296c separate Network and Plugins 2015-12-03 11:18:10 +01:00
ThomasV 90a2a049f4 network fix: callbacks were not called 2015-11-27 11:30:14 +01:00
ThomasV 042f8ef832 network: cache subscription responses 2015-11-26 11:26:01 +01:00
ThomasV 43df795b1f network: separate callbacks from unanswered_requests 2015-11-26 10:57:43 +01:00
ThomasV 2934fd17be fix websockets 2015-11-25 10:32:46 +01:00
Neil Booth ae4cfc9f0b Unregister network callbacks from QT gui
Rework the callback system in QT to make this easy, and avoid
leaking window references that prevent the window from being
GC-ed on close
2015-11-13 23:36:29 +09:00
Neil Booth 206e38fb7c Make use of trigger_callback easier to understand 2015-11-12 16:08:37 +09:00
Neil Booth 8cc3b58364 Allow syncronizer to be GC-ed
Proper fix for #1525.
Using python's GC module, I've verified that the daemon, when running,
now releases all verifiers, synchronizers and wallets - all the resources
we care about releasing.
2015-11-12 08:40:58 +09:00
ThomasV 6aefaf7b3e populate network.connecting before the thread is started (fixes KeyError in self.connecting.pop) 2015-10-17 07:07:10 +02:00
Neil Booth 58bd655f1d In debug mode, show every queued request 2015-09-12 12:13:42 +09:00
Neil Booth fb5e8068ce Simplify following on from prior dead code removal 2015-09-12 11:25:14 +09:00
Neil Booth f9547a194e Remove more dead code
As everything is in-process now, nothing sends
"network.*" messages.
2015-09-12 11:18:11 +09:00
Neil Booth fe2e731a70 Remove dead code 2015-09-12 10:54:20 +09:00
Neil Booth 3746050fe6 Subscribed address fix
Add an addr to the subcribed address set on receiving a response,
not on sending a request.
2015-09-10 13:32:00 +09:00
Neil Booth cbf9052dae Remove address caching 2015-09-10 12:57:04 +09:00
Neil Booth b14aae5ebc Clear self.interface when switching
When switching and the interface isn't immediately available,
we should clear self.Interface as otherwise requests will
still be going to it.
2015-09-09 22:13:09 +09:00
Neil Booth 6f1367fea6 Unify message IDs between network and interfaces
Previously network.py had its own idea of request IDs,
and each interface had its own which was sent on the wire.
The interface would jump through hoops to translate one
to the other.

This unifies them so that a message ID is passed when
queueing a request, in addition to the method and params.
network.py is now solely responsible for message ID management.

Apart from being simpler and clearer, this also should be faster
as there is much less data structure manipulation and rebuilding
happening.
2015-09-09 21:00:25 +09:00
Neil Booth abee263710 Remove obsolete server from DEFAULT_SERVERS 2015-09-07 10:39:55 +09:00
Neil Booth da5c18b2f9 Be patient whilst connecting
On startup we make several connections simultaneously.  Socket
maintenance code checks if we're not connected, and if not
switches to a connected interface if auto_connect.
Unfortunately this meant that we frequently didn't reconnect to
the prior good server on startup, because some other connection
would happen first and this code would decide to switch to it.

Instead, only switch if a connection attempt is not in progress.
If that times out at the O/S level the switch will happen.
2015-09-06 20:03:43 +09:00
Neil Booth b5f986ee56 Torwards sane signalling for exchange_rate plugin 2015-09-05 21:47:35 +09:00
Neil Booth 6c69849be9 Fix uninitialized var from select merge 2015-09-02 13:50:25 +09:00
Neil Booth cdcd4d7215 Fix 'tuple' object has no attribute 'copy'
Occurred when switching interfaces and there were unanswered
requests that need resending.  This bug isn't new; it's been
there since at least 3rd June.
2015-09-02 11:56:53 +09:00
Neil Booth 119aa5bf2e Move message so it doesn't repeat when connecting 2015-09-01 17:30:22 +09:00
Neil Booth 72f429c353 Remove unused callback 2015-09-01 14:41:06 +09:00
Neil Booth a5e0265010 Make exchange rate plugin a network thread job
This fixes a lot of thread error noise when closing down electrum.
2015-08-31 20:33:39 +09:00
Neil Booth 2ee506ac03 Fix typo. 2015-08-31 14:05:38 +09:00
Neil Booth 2d05e7d891 Merge the network and network_proxy 2015-08-31 12:00:38 +09:00
Neil Booth a056f9804b Notify when a chunk of headers is validated
And a couple of cosmetic changes.
This should fix #1379.
2015-08-25 14:27:53 +09:00
Neil Booth 49a48d52ac Use select. 2015-08-22 14:03:08 +02:00
ThomasV 713fa00d86 fix estimatefee for daemon 2015-08-07 10:54:32 +02:00
ThomasV 43880d452e dynamic fees 2015-08-05 15:45:28 +02:00
Eagle[TM] 4578777c29 network: Update default servers 2015-07-10 19:35:02 +02:00
Neil Booth 5acbe00cbf Suggested auto_connect daemon mode fix for #1336 2015-07-03 11:50:53 +09:00
ThomasV 604d5d432c sanitize server at the interface level (follow up to issue #1330) 2015-07-01 09:09:00 +02:00
ThomasV 0ac3aebb88 fix proxy setting issue #1330 2015-07-01 08:45:47 +02:00
ThomasV 118052d815 v2.4 will require protocol v0.10 2015-06-27 15:22:34 +02:00
ThomasV fdd43bd5ad fix issue in f307b18546 2015-06-24 09:35:54 +02:00
ThomasV f307b18546 Merge pull request #1268 from kyuupichan/blockchain_nothread
Make the blockchain class not a thread
2015-06-24 09:00:52 +02:00
ThomasV f894af90d7 fix deserialize_proxy. fixes #1309 2015-06-23 14:22:10 +02:00
ThomasV d6cdc085ea fix #1283 2015-06-11 10:03:26 +02:00
ThomasV e31ac7905d Clear address cache when interface changes. Send requests only if interface is connected. 2015-06-11 02:10:06 +02:00
Neil Booth 28f440350d Fix request handling.
Handle local requests immediately.
Defer those requiring connectivity until we have an interface.
2015-06-11 08:31:19 +09:00
ThomasV e517321f76 Network: fix handle_requests, must process requests even if we are not connected 2015-06-10 18:26:03 +02:00
ThomasV 6ea04e2d47 Network: Fix switch_to_interface (check that interface is connected) 2015-06-10 18:24:57 +02:00
Neil Booth caebdd0819 Need an interface to process a request.
Occasionally triggered with a race at start up, typically from
the verifier requesting a merkle root.
2015-06-04 11:22:57 +09:00
Neil Booth d16714a1db Make the blockchain class not a thread
Remove interface communication out of blockchain.py
into network.py.  network.py handles protocol requests
for headers and chunks.  blockchain.py continues to
handle their analysis and verification.

If an interface provides a header chain that doesn't
connect, it is dismissed, as per a previous TODO comment.

This removes a thread and another source of timeouts.
I see no performance issues with this when truncating the
blockchain.

Rename 'result' to 'header' for clarity.
2015-06-01 20:53:42 +09:00
Neil Booth 76355e66c8 Make interface status tri-state.
This allows us to distinguish between connecting and connected
state in interface.py (used to be done in network.py but that
had other issues).

This means we don't switch to a connecting server, and get_interfaces()
does not report connecting ones.
2015-06-01 18:22:03 +09:00
Neil Booth 2b66f0d459 Remove pending_servers, self.interfaces is now the complete set of
interfaces we have created.

Existing code has the concept of pending servers, where a connection
thread is started but has not sent a connection notification, and
and interfaces which have received the notification.

This separation caused a couple of minor bugs, and given the cleaner
semantics of unifying the two I don't think the separation is beneficial.
The bugs:

1) When stopping the network, we only stopped the connected interface
threads, not the pending ones.  This would leave Python hanging
on exit if we don't make them daemon threads.

2) start_interface() did not check pending servers before starting
a new thread.  Some of its callers did, but not all, so it was
possible to initiate two threads to one server and "lose" one thread.

Apart form fixing the above two issues, unification causes one more
change in semantics: we are now willing to switch to a connection
that is pending (we don't switch to failed interfaces). I don't
think that is a problem: if it times out we'll just switch
again when we receive the disconnect notification, and previously the
fact that an interface was in the interaces dictionary wasn't a
guarantee the connection was good anyway: we might not have processed
a pending disconnection notification.
2015-05-30 17:42:11 +09:00
Neil Booth 45a8740755 Common stale interface testing and switching
Three places used to test for lagging and switch.  Commonize the
code.  We test for lagging before autoconnect so lagging
diagnostics are output if not auto-connect.

Lagging diagnotics moved to server_is_lagging().
2015-05-27 00:42:43 +09:00
Neil Booth 39fe24b4d3 Rename auto_cycle to auto_connect in config
User config is updated if appropriate.
Add tests behaviour is as expected.
Just the one rename-it reference to auto_cycle remains.
2015-05-25 16:18:52 +09:00
Neil Booth 4f6d2f3d32 Put getting of auto_cycle into one place.
Default to False consistently; this may change the behaviour of
network.py's get_parameters().
2015-05-25 14:09:43 +09:00
Neil Booth 01d8f79a75 Clean up pick_random_server() and filter_protocol() and their
call sites.

Remove unused imports and redundant random pick of server
2015-05-24 21:07:35 +09:00
Neil Booth 89c1a1a0ab Improve logic in network.py's set_parameters()
1) For new proxy or protocol, restart the network and default to
   the requested server.
2) Otherwise if we aren't using the requested server, switch to it
3) Otherwise choose a random server if the requested server is
   stale and auto_connect is True

As switch_to_interface() now has another user, move the logic
there whereby we close the old interface in order to terminate
subscriptions, in order to have it in one place.
2015-05-23 23:33:17 +09:00
ThomasV 0fbbeb16be Merge pull request #1232 from kyuupichan/switch-or-start
switch_to_interface() to start interface if not connected
2015-05-23 07:30:00 +02:00
ThomasV b029589fc1 fix issue #1233 2015-05-22 20:47:51 +02:00
Neil Booth 2f34f3db21 Only start if not already in pending_servers
This was only in one call site previously, not both.
2015-05-22 16:29:56 +09:00
Neil Booth 31ffd4b381 switch_to_interface() to start interface if not connected
Two places currently have switch-to-or-start-interface logic.
Put that common logic into switch_to_interface().
2015-05-22 16:24:58 +09:00
Neil Booth 346e38674b Absorb add_interface and remove_interface
They are now only called from the same place; it's simpler
and clearer to put them inline.
2015-05-22 15:26:17 +09:00
ThomasV 0b201d98ab Merge pull request #1230 from kyuupichan/switch-random-if
Remove interfaces in one place only
2015-05-22 08:13:14 +02:00
Neil Booth 274965468e Remove interfaces in one place only
switch_to_random_interface used to do is_connected()
checks and remove interfaces when switching.  This
is redundant: interfaces are only added to self.interfaces
once in is_connected() state from process_if_notification().
When they are disconnected, a notification is also received
and process_if_notification() performs the removal.  Furthermore,
two other callers of switch_to_interface do not do explicit
is_connected() checks before calling it.
2015-05-22 15:01:11 +09:00
Neil Booth 4873c455b9 Add documentation string. Fix uninitialized f error.
Traceback (most recent call last):
      File "src/electrum/lib/network.py", line 411, in process_request
        out['result'] = f(*params)
    UnboundLocalError: local variable 'f' referenced before assignment
    [Network] network error local variable 'f' referenced before assignment
2015-05-22 14:14:06 +09:00
Neil Booth 05dd310431 Set 'connecting' status in one place.
Also means when switching to an already connected server our
status doesn't quickly change to connecting and back again.
2015-05-22 14:05:58 +09:00
Neil Booth 86626d8080 Consistency in handling of self.interface
switch_to_interface() becomes the common place where
self.interface is set; therefore self.interface is not None
precisely when self.default_server is connected.  Previously some
places required it to be connected and some didn't.  Also an
interface change now sends the 'updated' notification
consistently - previously some did and some didn't.

Have network_start() call start_interfaces() - this also means
network restarts now do this.

Fix apparent off-by-one in start_interfaces()
2015-05-22 09:13:09 +09:00
Neil Booth c918e74039 Put common network start and stop code in one place.
Prefer to use safer self.is_connected() as it checks interface
is not None.

Using common code gives small observable changes in behaviour:

 - slightly different print_error() messages
 - network restarts now enter status 'connecting' which they
   didn't before, which seems correct
 - status 'connecting' is done with set_status() rather than
   simply assigning the status, which seems more correct.  Now
   that the response_queue is available in the constructor this
   works; it used to fail with 'response_queue is not defined'
2015-05-22 07:52:59 +09:00
ThomasV 8620019f92 Merge pull request #1222 from kyuupichan/if_notification
Put interface notification handling in its own function.
2015-05-21 15:05:07 +02:00
ThomasV 5bd22d2378 follow-up to bd781d600b8ce2bc9dcebebbdb0fb60ad2fb892e: use pipe 2015-05-21 12:50:26 +02:00
Neil Booth c9a30eb5f2 Put interface notification handling in its own function. 2015-05-21 17:45:37 +09:00
Neil Booth bd781d600b Have queues passed to the network constructor.
This is somewhat cleaner as the proxy's pipe and network setup
was awkwardly interleaved.  It also means network's constructor
is free to use both; currently some code is working around the
fact that the response queue doesn't exist in the constructor.
2015-05-21 12:49:39 +09:00
ThomasV 2104e96a66 network: use get_nowait on one of the two queues 2015-05-19 10:22:25 +02:00
Neil Booth 63733ccd2a No need for thread to handle requests
Handle requests in the main loop.
Remove unused lock.
interface.py was reworked and send_request() no longer throws.
2015-05-19 14:29:10 +09:00
ThomasV e33bc2473b network: don't store unanswered request if result is in cache 2015-05-17 09:00:36 +02:00
ThomasV 6d0bc5d9b3 fix: nodes retry 2015-05-17 08:41:01 +02:00
ThomasV 44f06de796 network: when interface is disconnected, clear cache and resend unanswered requests 2015-05-15 14:47:59 +02:00
ThomasV a1d1999545 move interfaces maintenance to its own function 2015-05-08 20:13:18 +02:00
ThomasV f2c2f9d738 network: fix confusion between addresses and cached responses 2015-05-08 17:59:33 +02:00
ThomasV 233fd8ed77 revert 175bfae9e6. store last known height in wallet instead 2015-05-08 13:43:42 +02:00
ThomasV ffda5cd866 Merge pull request #1187 from kyuupichan/local_height
Move away from requiring network and blockchain objects to be able to re...
2015-05-06 17:45:42 +02:00
Neil Booth c07e956127 Pass the response_queue to the constructor, not start().
Removes an unnecessary Thread base-class override.  The python
documentation also strongly discourages overriding anything other
than run().
2015-05-05 20:37:25 +09:00
Neil Booth 9cf2eff16b Make is_connected into a member function. No change in logic. 2015-05-05 20:00:10 +09:00
Neil Booth 175bfae9e6 Move away from requiring network and blockchain objects to be able to request local height.
We store it in the config object instead of in the blockchain object.
The blockchain object now refers to its config, and calls refresh_height() to update it.
The network objects also refer to the config rather than the blockchain.

This is the first of many small steps to untangle the verifier from stored state and so
permit the history tab to work in offline mode.  The refactoring will simultaneously clean
up a lot of accumulated cruft.
2015-05-03 15:19:29 +09:00
ThomasV cdd5d6e130 fix #1136 2015-04-09 19:05:11 +02:00
ThomasV 911a60c02d separate timeouts for server and nodes retry 2015-04-02 15:12:01 +02:00
ThomasV 98cc9c53d1 do not write config file from network class 2015-04-02 10:50:09 +02:00
ThomasV a805afa900 save recent_servers in separate file 2015-04-02 10:12:51 +02:00
ThomasV cf0fcac9fa fix deserialize_server bug 2015-03-28 19:17:07 +01:00
ThomasV a4cb70649d fix synchronizer hanging when not connected. 2015-03-14 08:43:43 +01:00
ThomasV 72688a5cfa clean implementation of daemon threads 2015-03-13 23:04:29 +01:00
ThomasV 9e4eda24b5 fix #1082 2015-03-13 12:00:08 +01:00
ThomasV f32f1183fc print_error methods. request timeout for interface 2015-03-12 21:39:05 +01:00
ThomasV 1569cd0420 serialize/deserialize methods for servers 2015-03-12 18:06:28 +01:00
ThomasV c4d0314817 network: separate interface management from reconnection logic 2015-03-12 17:44:16 +01:00
ThomasV 799a08514b move proxy logic to network.py. reload socket module if proxy is disabled 2015-03-12 12:56:06 +01:00
ThomasV 0947eb7960 should test proxy_str. fixes issue #1073 2015-03-10 09:05:44 +01:00
ThomasV 73d8ba24d9 fix network connection issues 2015-03-07 22:47:25 +01:00
ThomasV e9b06f494d abort set_parameters if changes are not allowed by config 2015-03-01 07:27:05 +01:00
ThomasV 7a9141e509 deserialize network.proxy to prevent variability 2015-02-28 20:04:03 +01:00
ThomasV 510934d545 do not store protocol explicitly 2015-02-28 15:37:50 +01:00
ThomasV f489466709 fix: notify proxy when switching server 2015-02-28 14:08:58 +01:00
ThomasV 761871b900 sanitize server and protocol 2015-02-25 17:14:31 +01:00
ThomasV e389745491 remove appdata_dir and data_dir 2015-02-18 18:48:32 +01:00
ThomasV 03a88743a3 fix typo: stdout 2015-02-11 21:05:33 +01:00
ThomasV 3c6cfc8b70 disable server selector if server is passed from cmd line 2015-01-29 13:35:19 +01:00
ThomasV 8ca17a3e70 print traceback is an exception occurs in network.process_request 2015-01-29 11:32:58 +01:00
ThomasV 30763a6555 fix config: serialize/deserialize proxy 2015-01-29 11:21:17 +01:00
Tafelpoot d9c5250a6f removed trailing whitespace and fixed indentation in history widget 2014-10-21 19:05:51 +02:00
ThomasV b8f971fcd6 force reconnect after delay 2014-09-16 12:21:01 +02:00
ThomasV 90590f70ab reconnect to main server after timeout 2014-09-14 14:27:39 +02:00
Eagle[TM] a7cd8b5e9f Update default server list 2014-08-19 14:41:27 +02:00
ThomasV 854f49fbed fix number of interfaces being opened 2014-08-17 11:48:46 +02:00
ThomasV ecdb90b0b7 re-use pending_servers to avoid sending unnecessary notifications 2014-08-04 11:29:58 +02:00
ThomasV 642258ebaa notify about interfaces 2014-07-30 11:27:52 +02:00
ThomasV 858ff86660 network: disconnected retry interval 2014-07-30 10:43:15 +02:00
ThomasV ec5478c328 don't use pending_servers 2014-07-30 10:19:15 +02:00
ThomasV 517f649532 fix: missing break 2014-07-29 17:53:31 +02:00
ThomasV 0240b8c924 fix switch_to_random_interface 2014-07-29 14:26:19 +02:00
ThomasV 411a87e0a3 fix disconnection error 2014-07-29 14:19:23 +02:00
ThomasV 1c707d05d3 rm wrong assert clause 2014-07-29 12:48:05 +02:00
ThomasV 58c817f81a close interfaces on shutdown 2014-07-29 12:13:21 +02:00
ThomasV ed8f9666df remove interface.synchronous_get 2014-07-29 00:15:21 +02:00
ThomasV 312051a242 one more daemon thread 2014-07-28 15:49:41 +02:00
ThomasV fb0574c5a0 fix callbacks 2014-07-28 07:53:02 +02:00