Commit Graph

247 Commits

Author SHA1 Message Date
Peter Šurda 0b07b1c89a
Peer discovery updates
- allow loopback addresses, now you can bind different loopback IP
addresses on a single system and they will auto-cross-connect
- always listen for discovery on 0.0.0.0
- [network] - bind now also applies for the TCP socket as well as UDP
socket
- closing socket iterator fix
2017-08-09 17:34:47 +02:00
Peter Šurda e071efac1a
Typo 2017-08-09 17:29:48 +02:00
Peter Šurda cc955cd69d
Try new ports of binding fails
- API and BM protocol will try random ports for binding if those
configured are occupied
2017-08-09 17:29:23 +02:00
Peter Šurda 0324958e92
Peer discovery fixes
- incoming packets weren't correctly processed
2017-08-06 23:05:54 +02:00
Peter Šurda f338c00f8e
Change peer discovery tracking from queue to a dict
- with a queue, a situation could occur when new entries are appended
but nothing is polling the queue
2017-08-06 21:29:54 +02:00
Peter Šurda 4564d37f5b
Typo in previous commits 2017-08-06 21:26:25 +02:00
Peter Šurda 38872159fb
Typo in previous commit 2017-08-06 20:40:35 +02:00
Peter Šurda 5895dc2f1f
Asyncore Windows error handling
- windows behaves somewhat differently when using select
2017-08-06 20:39:14 +02:00
Peter Šurda 5108d08ac9
Windows asyncore error handler fix
- WSAEWOULDBLOCK is now checked on connect and accept
2017-08-06 18:18:21 +02:00
Peter Šurda 8f14fb05a1
UDP socket setsockopt fix 2017-08-05 10:14:15 +02:00
Peter Šurda a29f7534ee
Add EINTR handler for select and poll pollers 2017-07-21 09:06:02 +02:00
Peter Šurda 2530c62050
epoll throws IOError rather than select.error 2017-07-21 07:49:34 +02:00
Peter Šurda aa059d6f2f
Handle TLS errors in receivequeuethread
- well at least EBADF, it seems to happen sometimes
2017-07-21 07:47:18 +02:00
Peter Šurda 4f19c37fdc
Parser fix for multi-level arrays 2017-07-11 10:29:29 +02:00
Peter Šurda dcc181bf75
Asyncore processing thread synchronisation
- threre was a synchronisation problem where one thread could process
more data than another thread was expecting, leading to the thread
crashing
2017-07-10 23:18:58 +02:00
Peter Šurda f6d5d93bf2
Multiple receive queues fix
- forgot to commit busy handler
2017-07-10 20:52:11 +02:00
Peter Šurda db2d78c9b6
Make protocol decoder less recursive
- apparently, recursion has bad performance in Python, so the decoder is
now flat, except when parsing "version" command
2017-07-10 07:15:27 +02:00
Peter Šurda 853c8561ec
Per connection node id part 2
- forgot to include this in the previous commit
2017-07-10 07:12:52 +02:00
Peter Šurda 3941b39136
Randomise node id
- in order to detect if it's connected to to itself, PyBitmessage now
uses a per-connection id rather than a global one
2017-07-10 07:10:05 +02:00
Peter Šurda bdf61489ae
Allow multiple ReceiveQueue threads
- defaults to 3
2017-07-10 07:08:10 +02:00
Peter Šurda f088e0ae21
Change thread names
- not needed to have "Thread" in the name of a thread
2017-07-10 07:05:50 +02:00
Peter Šurda 4fce01e34a
Less data transferred in invThread and addrThread 2017-07-08 18:02:47 +02:00
Peter Šurda 2df9598774
Asyncore update: Fix incoming connections
- dereferencing wasn't done correctly for incoming connections
2017-07-08 07:33:29 +02:00
Peter Šurda 2d7d9c2f92
Asyncore update
- request downloads in bigger chunks
- don't put whole objects into the receiveDataQueue
2017-07-08 06:54:25 +02:00
Peter Šurda 0f3a69adf4
Asyncore update: remove references to deleted files 2017-07-08 06:53:20 +02:00
Peter Šurda 5ae1b6d865
Asyncore update: remove obsolete files 2017-07-08 06:52:17 +02:00
Peter Šurda a98b8690d3
Asyncore fixes
- fix broken loops
- optimise I/O tests
2017-07-07 07:55:29 +02:00
Peter Šurda ba4162d7fe
Asyncore update
- get rid of per-connection writeQueue/receiveQueue, and instead use
strings and locking
- minor code cleanup
- all state handlers now should set expectBytes
- almost all data processing happens in ReceiveDataThread, and
AsyncoreThread is almost only I/O (plus TLS). AsyncoreThread simply
puts the connection object into the queue when it has some data for
processing
- allow poll, epoll and kqueue handlers. kqueue is untested and
unoptimised, poll and epoll seem to work ok (linux)
- stack depth threshold handler  in decode_payload_content, this is
recursive and I think was causing occasional RuntimeErrors. Fixes #964
- longer asyncore loops, as now data is handled in ReceiveDataThread
- randomise node order when deciding what to download. Should prevent
retries being stuck to the same node
- socks cleanup (socks5 works ok, socks4a untested but should work too)
2017-07-06 19:45:36 +02:00
Peter Šurda fe0664640e
Migrate antiIntersectionDelay to asyncore
- implemented by ignoring getdata during the delay rather than sleeping
as it was in the threaded model
- it can happen that a valid getdata request is received during the
delay. A node should be implemented in a way that retries to download,
that may not be the case with older PyBitmessage versions or other
implementations
2017-07-05 09:27:52 +02:00
Peter Šurda fc19e4119a
Download thread updates
- now tracks downloads globally too, so it doesn't request the same
object from multiple peers at the same time
- retries at the earliest every minute
- stops trying to download an object after an hour
- minor fixes in retrying downloading invalid objects
2017-07-05 09:25:49 +02:00
Peter Šurda 846fced0a2
Remove obsolete inactive code 2017-07-05 09:19:56 +02:00
Peter Šurda d086781ce8
AddrQueue fix
- forgot to commit import
2017-07-05 09:19:18 +02:00
Peter Šurda a0bbd21efc
Add ratings to peers
- outbound peers now have a rating
- it's also shown in the network status tab
- currently it's between -1 to +1, changes by 0.1 steps and uses a
hyperbolic function 0.05/(1.0 - rating) to convert rating to
probability with which we should connect to that node when randomly
chosen
- it increases when we successfully establish a full outbound connection
to a node, and decreases when we fail to do that
- onion nodes have priority when using SOCKS
2017-07-05 09:17:01 +02:00
Peter Šurda 9d09f9f3ce
Reduce severity of socks connectivity errors
- Fixes #1024
- Fixes #1019
2017-07-05 09:07:00 +02:00
Peter Šurda e00a02206b
AddrThread
- this thread is for spreading new/updated addresses in active
connections, analogous to the InvThread
- it doesn't do anything yet, this is just a dummy queue at the moment
2017-07-05 08:57:44 +02:00
Peter Šurda cc3cf77759
New class multiqueue
- to be used for invthread and addthread
- updated invthread for multiqueue
2017-06-27 13:25:12 +02:00
Peter Šurda 189578cba3
Asyncore proxy fixes
- SOCKS5 now seems to work, SOCKS4a untested
2017-06-24 12:23:56 +02:00
Peter Šurda 916b85c862
Connection pool cleanup
- minor code quality improvement
2017-06-24 12:23:16 +02:00
Peter Šurda 0dc0b22974
Expired / Stream mismatch / duplicate object error handling
- cleanup of the code
2017-06-24 12:22:41 +02:00
Peter Šurda 0a79490e2c
Known nodes maximum configurable part 2 2017-06-24 12:21:42 +02:00
Peter Šurda d57b0c55ee
Object validator trigger moved
- from bmproto to bmobject
2017-06-24 12:21:06 +02:00
Peter Šurda dc5a91f326
Remove stack depth warnings
- I was never able to trigger them
2017-06-24 12:19:19 +02:00
Peter Šurda e9edf70d3a
TLS updates
- save TLS version
- minor TLS error handling updates
2017-06-24 12:18:15 +02:00
Peter Šurda 26eb54a82e
Network status updates
- now lists each node with its info instead of a per-stream summary
2017-06-24 12:16:12 +02:00
Peter Šurda 2685fe29b1
Code quality improvements 2017-06-24 12:13:35 +02:00
Peter Šurda 0cc8589b27
Asyncore updates
- should prevent the same object being re-requested indefinitely
- locking for object tracking
- move SSL-specific error handling to TLSDispatcher
- observe maximum connection limit when accepting a new connection
- stack depth test (for debugging purposes)
- separate download thread
- connection pool init moved to main thread
2017-06-21 12:16:33 +02:00
Peter Šurda a3a55e53c4
UDP Socket dict address fix
- fixes #1008
2017-06-11 14:11:39 +02:00
Peter Šurda cba749088a
Asyncore updates
- mainly work on proxy support, but it's still not fully working
- minor bugfixes
2017-06-10 10:13:49 +02:00
Peter Šurda 7bde4e9445
Missing module name in bmproto 2017-06-04 10:25:16 +02:00
Peter Šurda e8d9a7f183
Asyncore connect handling
- minor improvements in handling of connect events so that it's not
processed twice
2017-06-03 16:30:05 +02:00
Peter Šurda a9c0000c17
Treat some invalid objects as received
- update to 6044df5adf
- objects that are expired or in wrong stream are not re-requested
anymore, even if they aren't stored in the inventory
- the previous option "acceptmismatch" now only affects whether such
objects are stored in the inventory
2017-06-03 16:29:21 +02:00
Peter Šurda 6044df5adf
Optional storing of expired and off-stream objects
- a new config file option, network/acceptmismatch, allows the inventory
to store objects that expired or are from a stream we're not
interested in. Having this on will prevent re-requesting objects that
other nodes incorrectly advertise. It defaults to false
2017-06-02 15:43:35 +02:00
Peter Šurda d75d920a68
Asyncore updates
- clean object tracking dictionaries in the cleaner thread
- clean up close / handle_close
- add locking to tracking dictionaries
2017-06-02 07:09:35 +02:00
Peter Šurda 4c17a18006
Don't send invs to unestablished connections 2017-05-31 23:34:06 +02:00
Peter Šurda 18988ae2e6
Asyncore updates
- performance optimisation, reduce number of loops when waiting
for protocol headers / commands
2017-05-31 10:17:36 +02:00
Peter Šurda d9e3349eeb
Fix own IP detection
- minor bug in the previous commit
2017-05-31 00:22:07 +02:00
Peter Šurda f23c169eec
Don't connect to myself
- track local IP+port of incoming connections and don't connect
to them in the future
2017-05-31 00:04:21 +02:00
Peter Šurda fa9811f426
Asyncore update
- duplicate checking implemented
- connection pool vs. socket closing cleanup
2017-05-30 23:53:43 +02:00
Peter Šurda abaa2c72e5
typo 2017-05-29 15:04:22 +02:00
Peter Šurda 11d02b1e41
typo 2017-05-29 14:59:42 +02:00
Peter Šurda 3a543efd83
Typo 2017-05-29 14:54:13 +02:00
Peter Šurda 7f381c0c25
Asyncore update
- incoming object handling fix
2017-05-29 14:52:31 +02:00
Peter Šurda 1ccfd41c3f
Asyncore updates
- fix connected to myself check
2017-05-29 14:41:02 +02:00
Peter Šurda 0aa5dbd958
Asyncore update
- shutdown fix
2017-05-29 14:35:08 +02:00
Peter Šurda bdaa939e2c
ENOTSOCK fix 2017-05-29 13:39:26 +02:00
Peter Šurda 97c44b97f4
Asyncore update
- handle WSAENOTSOCK
2017-05-29 13:14:25 +02:00
Peter Šurda a5c1b0c529
Asyncore fixes
- better handling of WSA* checks on non-windows systems
- handle EBADF on Windows/select
- better timeouts / loop lengths in main asyncore loop and
spawning new connections
- remove InvThread prints
2017-05-29 12:56:59 +02:00
Peter Šurda 74f1a74a8c
Make SO_REUSEPORT optional
- apparently not available on Windows
2017-05-29 11:30:56 +02:00
Peter Šurda 02a07e5119
Asyncore update
- default to true (original attempt didn't work correctly)
2017-05-29 03:16:14 +02:00
Peter Šurda 65bb6648e7
Asyncore updates
- fix crash in inv thread
- more prints changed into logger
- minor fixes
2017-05-29 00:47:41 +02:00
Peter Šurda c85d52b8e8
Asyncore updates
- asyncore is now on by default
- inv announcements implemented
- bandwidth limit implemented / fixed
- stats on download / upload speed now work
- make prints into logger
- limit knownNodes to 20k as it was before
- green light fixed
- other minor fixes
2017-05-29 00:24:07 +02:00
Peter Šurda 5d4e1e2007
asyncore fixes
- bm headers and commands are only read up to expected length.
On a very fast connection (e.g. local VM), reading verack
also read a part of the TLS handshake
- some debugging info moved from print to logger.debug
- tls handshake cleanup
2017-05-27 22:30:30 +02:00
Peter Šurda 21f6d38ec2
Asyncore fixes
- TCP fixes
2017-05-27 21:52:56 +02:00
Peter Šurda 99e714c432
UDP socket bugfixes 2017-05-27 20:43:27 +02:00
Peter Šurda fa9ad537a5
Add task_done to asyncore-related queues 2017-05-27 19:39:19 +02:00
Peter Šurda f8b4b427fc
Asyncore update
- bugfixes
- UDP socket for local peer discovery
- new function assembleAddr to unify creating address command
- open port checker functionality (inactive)
- sendBigInv is done in a thread separate from the network IO
thread
2017-05-27 19:09:21 +02:00
Peter Šurda e309a1edb3
Asyncore update
- separate queue for processing blocking stuff on reception
- rewrote write buffer as a queue
- some addr handling
- number of half open connections correct
2017-05-25 23:04:33 +02:00
Peter Šurda 9683c879bc
Asyncore update
- Network status UI works but current speed isn't implemented yet
- Track per connection and global transferred bytes
- Add locking to write queue so that other threads can put stuff
there
- send ping on timeout (instead of closing the connection)
- implement open port checker (untested, never triggered yet)
- error handling on IO
2017-05-25 14:59:18 +02:00
Peter Šurda edcba9982b
Asyncore getdata processing performance improvement
- no need to query DB for existence of each entry
2017-05-24 21:35:50 +02:00
Peter Šurda fa56ab3e6f
Asyncore update
- better error handling
- bug fixes
- remove some debug output
2017-05-24 21:15:36 +02:00
Peter Šurda bafdd6a93a
Allow making outbound connections in asyncore 2017-05-24 16:54:33 +02:00
Peter Šurda d635e515b9
Big Asyncore update
- most of the stuff is done so it partially works
- disabled pollers other than select (debugging necessary)
- can switch in the settings, section network, option asyncore (defaults
to False)
2017-05-24 16:51:49 +02:00
Peter Šurda d9d3515905
Node class, WIP
- for new network subsystem
2017-05-07 20:16:49 +02:00
Peter Šurda 96d58f3c11
Asyncore update (WIP) 2017-04-16 18:27:15 +02:00
Peter Šurda 51aeb284ca
Async network IO updates
- WIP
2017-04-04 10:46:01 +02:00
Peter Šurda 46c9ea9403
Async network updates (WIP)
- cleaner command handling
- separating into header and command handling
- incoming connection handler
- bugfixes and more debug information
2017-03-20 18:32:26 +01:00
Peter Šurda 49869d0b56
Networking subsystem updates
- version command struct for faster unpacking
- increase read buffer to 2MB to allow a full command to fit
- initial bitmessage protocol class (WIP)
- error handling
- remove duplicate method
2017-03-11 11:12:08 +01:00
Peter Šurda a1d1114cb2
New network subsystem updates
- auto-select select/poll/epoll/kqueue depending on what's available
2017-03-10 23:56:38 +01:00
Peter Šurda 998935be5f
New network subsystem, WIP
- finished proxy design
- socks4a and socks5 implemented
- authentication not tested
- resolver for both socks4a and socks5
- http client example using the proxy
2017-03-10 23:11:57 +01:00
Justin Ramos b50198afb5
changes needed to get current code to run 2017-02-25 00:06:04 -06:00
Peter Šurda 2cc4435cfc
Imports, typos, syntax errors
- remove obsolete imports
- add missing imports
- fix typos
- fix syntax errors
- thanks to landscape.io for report
2017-02-08 14:19:02 +01:00
Peter Šurda 810e50a040
Fix minor issues
- landscape.io complained
- obsolete imports
- ciphers -> self.ciphers
2017-01-12 07:26:04 +01:00
Peter Šurda 5ceb920bd6
TLS tuning
- allow TLS > 1.0 with python >= 2.7.9
- tune ssl_context with python >= 2.7.9
2017-01-11 20:47:27 +01:00
Peter Šurda ac348e4e6b
Fixes and refactoring
- fixes errors introduced in the earlier refactoring
- more variables moved to state.py
- path finding functions moved to paths.py
- remembers IPv6 network unreachable (in the future can be used to skip
  IPv6 for a while)
2017-01-11 17:00:00 +01:00
Peter Šurda 085e335969
Proxy update (for the new network subsystem) 2017-01-10 21:22:22 +01:00
Peter Šurda 75090abaaf
Advanced dispatcher class
- generic class the new asyncore-based network subsystem that handles
  buffered data transfer
2017-01-10 21:20:49 +01:00
Peter Šurda 9509552663
New network backend (WIP, not integrated)
- current snapshot of the new network backend code
- not working yet, just base classes and no integration
2016-12-01 16:48:04 +01:00