Commit Graph

233 Commits

Author SHA1 Message Date
ThomasV 305843999e Relicensing 2016-02-24 10:20:30 +01:00
ThomasV fe9ec6de06 reformatting 2016-01-26 13:51:47 +01:00
ThomasV 614f3df4b8 Revert "Use ssl.PROTOCOL_TLSv1 on client side to avoid SSLv23"
This reverts commit 4731418af9.
2015-10-27 10:44:36 +01:00
Kefkius f329143733 Fix typo in Connection docstring
Fix a small typo in Connection docstring.
2015-10-06 16:03:24 -04: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 93b99ebded Handy new class PrintError
Saves adding "def print_error" to endless classes.
2015-09-06 21:40:00 +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 748662dede Add a debugging traceback. 2015-08-31 14:38:19 +09:00
Neil Booth 49a48d52ac Use select. 2015-08-22 14:03:08 +02:00
ThomasV 85d9b8aa8d fix: dePem cert before parsing 2015-08-07 11:58:59 +02:00
ThomasV ca3c320ef4 simplify x509 constructor 2015-08-07 11:39:30 +02:00
ThomasV 476d198be9 fix missing occurences of X509.parse 2015-08-04 18:31:08 +02:00
ThomasV 380bccacf0 request_queue.put should never block, because maxsize is not set 2015-07-31 20:11:12 +02:00
Eagle[TM] 4731418af9 Use ssl.PROTOCOL_TLSv1 on client side to avoid SSLv23 2015-07-30 20:40:05 +02:00
Roman Zeyde 5fbd7553ed interface: fix check_host_name() pattern matching
The existing pattern matching code:

    val.find('*.') == 0 and name.find(val[1:]) + len(val[1:]) == len(name)

will return True in the following case:

   val = '*.host.com'
   name = 'blah.org'

since string.find() will return -1, len(val[1:]) == 9 and len(name) == 8.
2015-07-26 18:11:30 +03:00
neocogent 8792301846 restrict to *. only, add DN support also 2015-07-17 11:17:43 +07:00
neocogent 3c563b85ad adjust comment about wildcards 2015-07-17 04:22:39 +07:00
neocogent 59c231808f add wildcard ssl support 2015-07-17 04:03:40 +07:00
Roman Zeyde 9c06bee8c7 interface: slow_parse() is not defined for X509 2015-07-01 16:54:11 +03:00
ThomasV 604d5d432c sanitize server at the interface level (follow up to issue #1330) 2015-07-01 09:09:00 +02:00
Neil Booth 2f2e468d0a SocketPipe shouldn't close the socket.
This is a layering violation - the SocketPipe doesn't own
the socket and provides no other way to close the socket, leading
to unnecessary complexity like that in interface.py.

I looked at deamon.py and NetworkProxy - the two other users,
and they don't close the sockets explicitly, just let them be
garbage collected.
2015-06-04 16:30:59 +09:00
Neil Booth ab2f80c3e0 Fix couple of minor socket issues
Set timeout and socket options on all simple sockets.  At present
some code paths can miss it, such as when the SSL certificate is
CA-signed.

Add a missing check for failure.
2015-06-02 18:13:36 +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
ThomasV 5c73bc5bc7 interface: init ping_time with 0 so that the client sends version message 2015-05-19 11:28:30 +02:00
ThomasV 2a92a310ba typo 2015-05-08 17:47:04 +02:00
ThomasV 8c07bdc3bc do not timeout if interface is receiving data 2015-05-08 17:45:59 +02:00
Neil Booth 97b5f6d6a3 Fix two races in interface.py.
First, close the socket from the thread itself rather than from
the stop() function.  This prevents another thread closing the
socket that the interface thread is simultaneously using.

Second, it occasionally would happen that the parent thread such as
network.py start() an interface, do a send_request() and timeout
waiting for a response (timeouts are 0.1s).  It would check
is_connected(), get False, and assume the connection has failed.
In fact the thread hadn't even been scheduled or gotten around to
completing the socket connection.  Fix by having self.connected
start out True.  If the connection fails or times out, we set
connected to False soon enough.

Finally for correctness we need to deepcopy a send_request() rather
than take a reference to it.
2015-05-08 07:32:31 +09:00
ThomasV 8656785aa7 fix: use request_time for interface timeout 2015-05-06 17:25:29 +02:00
ThomasV 45fd3ef343 interface: send from same thread and simplify timeouts 2015-05-06 16:42:18 +02:00
ThomasV 78f5dbb72e revert c64e0c0e64 2015-05-06 12:13:21 +02:00
Neil Booth 6171779442 Move response getting to its own function.
This makes the operation of run() more clear.
No essential change in functionality.
2015-05-06 14:35:55 +09:00
Neil Booth 0cfcd2c7b2 Remove self.lock
It is now unused; all necesary locking is done by the Queue objects.
2015-05-05 21:57:07 +09:00
Neil Booth c64e0c0e64 Send requests only from the interface thread.
Currently requests are sent from the requestor's thread.  The lock is
not properly held where necessary so this is not thread-safe.  For example
it can race with the thread stopping and closing the socket the
requestor is trying to use to send with.

Resolve such races by having send_request() simply queue the requests,
which are asynchronously sent from the interface thread itself.
2015-05-05 21:36:34 +09:00
Neil Booth 6920747a5d Move ping functionality into its own function.
First step in cleaning up the run() function.
Calls stop() rather than setting is_connected to False on
case of timeout, which cleanly closes the socket.
2015-05-05 20:46:34 +09: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 4d55cb9528 First of several incremental patches tightening up interface.py.
Remove some unneeded imports, a constant and a line of dead code.
Document the current external API interface.py provides.
2015-05-05 14:02:51 +09:00
ThomasV f32f1183fc print_error methods. request timeout for interface 2015-03-12 21:39:05 +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 ae7405a10f remove old http interface code, not used 2015-03-12 11:55:10 +01:00
ThomasV 92987d9019 add comment about proxy side effect 2015-03-10 09:43:22 +01:00
ThomasV 73d8ba24d9 fix network connection issues 2015-03-07 22:47:25 +01:00
ThomasV fdaf4e42a9 print reason if connection fails 2015-02-28 19:45:10 +01:00
ThomasV b3364b87d1 interface: don't show traceback on error 104 2015-02-21 14:45:09 +01:00
ThomasV 992a634a77 serialize: handle case where proxy is None 2015-01-29 11:30:42 +01:00
ThomasV 30763a6555 fix config: serialize/deserialize proxy 2015-01-29 11:21:17 +01:00
ThomasV c225795793 use ssl.PROTOCOL_SSLv23 2014-10-31 14:59:59 +01:00
Tafelpoot d9c5250a6f removed trailing whitespace and fixed indentation in history widget 2014-10-21 19:05:51 +02:00
ThomasV 60e5450a0e rm print statement 2014-09-28 23:20:52 +02:00
ThomasV 0c0da6a36d use certs from request module in interface.py 2014-09-28 23:19:52 +02:00