Merge lp:~aj00200/anonplus/bug-927447 into lp:anonplus

Proposed by aj00200
Status: Merged
Merge reported by: aj00200
Merged at revision: not available
Proposed branch: lp:~aj00200/anonplus/bug-927447
Merge into: lp:anonplus
Diff against target: 338 lines (+108/-35)
7 files modified
src/libs/friends.py (+26/-3)
src/libs/socks.py (+4/-3)
src/tunnels/base.py (+1/-1)
src/tunnels/directudp.py (+21/-13)
src/tunnels/tor.py (+50/-12)
src/uis/web/handler.py (+1/-1)
src/vomun.py (+5/-2)
To merge this branch: bzr merge lp:~aj00200/anonplus/bug-927447
Reviewer Review Type Date Requested Status
aj00200 Disapprove
Review via email: mp+91606@code.launchpad.net

Commit message

Fixed bug #927447 in the web UI reply code.

Description of the change

Fixed bug #927447 in the web UI reply code.

To post a comment you must log in.
Revision history for this message
aj00200 (aj00200) :
review: Approve
Revision history for this message
aj00200 (aj00200) wrote :

It seems that this is a branch of the wrong code for merging into lp:anonplus.

review: Disapprove
Revision history for this message
aj00200 (aj00200) wrote :

I merged r219 on the branch which is the needed patch to fix this bug.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/libs/friends.py'
2--- src/libs/friends.py 2012-01-24 22:39:48 +0000
3+++ src/libs/friends.py 2012-02-06 05:10:23 +0000
4@@ -130,12 +130,13 @@
5 def connect(self):
6 '''Connect to the friend'''
7 self.wconnection.connect()
8+ self.connected = True
9
10 def send(self, data, system=0):
11 '''Send data to the friend. This will try to establish a connection, if
12 not yet connected.
13 '''
14- if self.wconnection == None:
15+ if not self.connected:
16 self.connect()
17 message = self.encryption.encrypt(data)
18 self.wconnection.send(message)
19@@ -178,12 +179,34 @@
20 }''' % (self.name, self.keyid, self.ip, self.port, self.tunnel_type)
21
22 def __decrypt(self):
23+ '''Use this friend object's encryption object to decrypt the
24+ data stored in self.data.
25+ '''
26 self.data = self.encryption.decrypt(self.data)
27- print('Decrypted data: %s' % self.data)
28+ broadcast('logthis', 'Decrypted data: %s' % self.data, level = 0)
29
30 def __str__(self):
31 return '<friend %s on %s:%i with id %s>' % (
32 self.name, self.ip, self.port, self.keyid)
33+
34+def identify(indata, tunnel):
35+ '''Identify what the source IP of an incomming packet is based on the
36+ packet that is sent. Please see the friend-identification blueprint:
37+ https://blueprints.launchpad.net/anonplus/+spec/friend-identification
38+ '''
39+ nodekey = libs.encryption.rsa.Encryption(libs.config['nodekey'])
40+ data = nodekey.decrypt(indata)
41+ packets, leftovers = parse_packets(data)
42+ packet = packets[0]
43+
44+ # Collect information from the packet
45+ src_key = packet.key
46+ # TODO: get IP address out of packet fields
47+
48+ friend = get_friend_by_key(src_key)
49+ friend.wconnection = tunnel
50+
51+ # TODO: use the key property to reply 0x0002
52
53
54 ## API section
55@@ -261,4 +284,4 @@
56 try:
57 del libs.globals['friends'][keyid]
58 except:
59- broadcast('logthis', 'Friend %s does not exist.' % keyid)
60\ No newline at end of file
61+ broadcast('logthis', 'Friend %s does not exist.' % keyid)
62
63=== modified file 'src/libs/socks.py'
64--- src/libs/socks.py 2011-12-18 22:29:14 +0000
65+++ src/libs/socks.py 2012-02-06 05:10:23 +0000
66@@ -59,10 +59,11 @@
67 return repr(self.value)
68
69 class Socks5Error(ProxyError):
70- def __init__(self, value):
71+ def __init__(self, value, errno = -1):
72 self.value = value
73+ self.errno = errno
74 def __str__(self):
75- return repr(self.value)
76+ return 'errno=%s, %s' % (self.errno, self.value)
77
78 class Socks4Error(ProxyError):
79 def __init__(self, value):
80@@ -233,7 +234,7 @@
81 # Connection failed
82 self.close()
83 if ord(resp[1])<=8:
84- raise Socks5Error(ord(resp[1]),_generalerrors[ord(resp[1])])
85+ raise Socks5Error(_generalerrors[ord(resp[1])], errno=ord(resp[1]))
86 else:
87 raise Socks5Error(9,_generalerrors[9])
88 # Get the bound address/port
89
90=== modified file 'src/tunnels/base.py'
91--- src/tunnels/base.py 2011-10-30 18:06:34 +0000
92+++ src/tunnels/base.py 2012-02-06 05:10:23 +0000
93@@ -5,7 +5,7 @@
94 '''
95 def connect(self, address, port):
96 '''Use this tunnel to connect to `address`:`port`'''
97- pass
98+ return True # Method not overwritten. No connection needed?
99
100 def disconnect(self, nodeid):
101 '''Disconnect from a node at `nodeid`'''
102
103=== modified file 'src/tunnels/directudp.py'
104--- src/tunnels/directudp.py 2012-01-11 19:34:49 +0000
105+++ src/tunnels/directudp.py 2012-02-06 05:10:23 +0000
106@@ -29,11 +29,6 @@
107 self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
108 self.sock.connect((node.ip, node.port))
109
110- self.data = ""
111- self.packages = {}
112-
113-
114- #handshake is ended in friends.handle_packets
115 def send(self, message):
116 broadcast('logthis', 'Sending: ' + message, level = 0)
117 self.sock.send(message)
118@@ -41,8 +36,6 @@
119 def disconnect(self):
120 '''Do nothing, UDP does not need to close any connections.'''
121 pass
122-
123-
124
125 class Listener(libs.threadmanager.Thread):
126 '''Listen for UDP connections on our port'''
127@@ -52,17 +45,31 @@
128 self.sock.bind(('', port)) # TODO: bind other addresses
129 self.sock.setblocking(False)
130
131+ self.registered = {}
132+
133+ def register(self, ip, connection):
134+ '''Hook and IP address to a connection object so that when we
135+ get a packet from a known IP, we can send it to the proper
136+ connection object.
137+ '''
138+ self.registered[ip] = connection
139+
140 def run(self):
141 while not self._stop.isSet():
142 try:
143 data = self.sock.recvfrom(4096)
144 ip = data[1][0]
145- friend = libs.friends.get_friend_by_ip(ip)
146- friend.connection = self.sock
147- friend.data += data[0] # Send data to the Friend object
148- broadcast('logthis', 'UDP recv: %s' % data[0], level = 0)
149- friend.parse_packets()
150- friend.connection = self.sock
151+
152+ if ip in self.registered:
153+ self.registered[ip].get_data(data)
154+
155+ else:
156+ friend = libs.friends.get_friend_by_ip(ip)
157+ friend.connection = self.sock
158+ friend.data += data[0] # Send data to the Friend object
159+ broadcast('logthis', 'UDP recv: %s' % data[0], level = 0)
160+ friend.parse_packets()
161+ friend.connection = self.sock
162
163 except socket.error as error:
164 if error.errno == 11: # No new messages
165@@ -75,6 +82,7 @@
166
167
168 def start():
169+ '''Start the tunnel. Create a Listener thread and start it.'''
170 listener = Listener()
171 listener.start()
172 libs.threadmanager.register(listener)
173
174=== modified file 'src/tunnels/tor.py'
175--- src/tunnels/tor.py 2012-01-24 22:39:48 +0000
176+++ src/tunnels/tor.py 2012-02-06 05:10:23 +0000
177@@ -1,6 +1,8 @@
178 '''Tunnel to use to connect to other nodes over Tor.'''
179-import socks
180+from libs import socks
181+import socket
182 import libs.threadmanager
183+from libs.events import broadcast
184
185 class Tunnel(object):
186 '''Base Tunnel class. Should be subclassed by other tunnels for
187@@ -8,30 +10,63 @@
188 '''
189 def __init__(self, node):
190 self.node = node
191- # TODO: need to get node onion address and port
192+ self.is_connected = False
193+
194+ self.connection = Connection(node)
195
196 def connect(self):
197 '''Use this tunnel to connect to `address`:`port`'''
198- self.connection = Connection(self.node)
199+ success = self.connection.connect()
200+ if success:
201+ self.is_connected = True
202+ else:
203+ self.is_connected = False
204+ return True
205+
206+ def connected(self):
207+ '''Returns True if this tunnel is connected.'''
208+ return self.is_connected
209
210 def disconnect(self, nodeid):
211 '''Disconnect from a node at `nodeid`'''
212 pass
213
214 def send(self, message):
215- self.connection.send(message)
216+ '''Check if this Tunnel is connected. If it is, try to send the
217+ message parameter to the other node.
218+ '''
219+ if self.connected:
220+ self.connection.send(message)
221+ else:
222+ self.connect()
223+
224+ if self.connected:
225+ self.connection.send(message)
226+ else:
227+ return False
228
229 class Connection(object):
230 '''A class to store a connection to a peer'''
231 def __init__(self, node):
232+ # node.ip must not be unicode because of this bug in python-socks:
233+ # https://code.google.com/p/httplib2/issues/detail?id=179
234+ self.node = (str(node.ip), node.port)
235 self.sock = socks.socksocket()
236- self.sock.setproxy(socks.PROXY_TYPE_SOCKS5, addr='localhost',
237+ self.sock.setproxy(socks.PROXY_TYPE_SOCKS5, addr='127.0.0.1',
238 port=9050, rdns=True)
239- # node.ip must not be unicode because of this bug in python-socks:
240- # https://code.google.com/p/httplib2/issues/detail?id=179
241- self.sock.connect((str(node.ip), node.port))
242+
243+ def connect(self):
244+ try:
245+ self.sock.connect(self.node)
246+
247+ except socks.Socks5Error as error:
248+ if error.errno == 2: # not connected
249+ return False
250+
251+ return True
252
253 def send(self, message):
254+ '''Send a message to the connected node over Tor.'''
255 broadcast('logthis', 'Sending: ' + message, level = 0)
256 self.sock.send(message)
257
258@@ -41,20 +76,23 @@
259 port unless otherwise set. We have no way to associate which friend
260 this is so it must be added to the handshake somehow.
261 '''
262- def __init__(self, port=1337):
263+ def __init__(self, port=4040):
264 super(Listener, self).__init__()
265 self.sock = socket.socket()
266 self.sock.bind(('localhost', port))
267 self.sock.listen(2)
268- self.sock.setblocking(False)
269
270 def run(self):
271 while not self._stop.isSet():
272 # TODO: find out which friend this is without IP address
273- connection = self.sock.accept() # TODO: this blocks!!!!!
274+ connection = self.sock.accept() # TODO: blocks shutdown
275+ print('----------------------------------')
276+ print('Got a connection on the Tor tunnel')
277 # TODO: convert this connection to a Connection object!!
278+ # TODO: send this connection to libs.friends
279
280 def start():
281+ '''Start the Tor tunnel and create a Listener object.'''
282 listener = Listener()
283 listener.start()
284- libs.threadmanager.register(listener)
285\ No newline at end of file
286+ libs.threadmanager.register(listener)
287
288=== modified file 'src/uis/web/handler.py'
289--- src/uis/web/handler.py 2012-01-15 16:14:19 +0000
290+++ src/uis/web/handler.py 2012-02-06 05:10:23 +0000
291@@ -107,7 +107,7 @@
292 connection.send_response(301)
293 connection.send_header('Location', 'http://localhost:7777/')
294 connection.end_headers()
295- connections.wfile.write('Redirecting')
296+ connection.wfile.write('Redirecting')
297 elif path == '/friends.html':
298 connection.send_response(200)
299 connection.send_header('Content-type', 'text/html')
300
301=== modified file 'src/vomun.py'
302--- src/vomun.py 2012-01-24 22:39:48 +0000
303+++ src/vomun.py 2012-02-06 05:10:23 +0000
304@@ -2,15 +2,16 @@
305 '''Start the program. Load segments of the program that need to be
306 started and run them.
307 '''
308-import atexit, time, webbrowser, sys
309+import atexit, webbrowser, sys
310
311-from libs import config, events, friends, globals, logs
312+from libs import config, events, friends, globals
313 from libs import storage, threadmanager
314 from libs.morado import morado
315 import tunnels
316 import uis.web.manager
317
318 def start():
319+ '''Setup various services and classes used by the software.'''
320 morado.start()
321 friends.load_friends()
322 storage.manager.start()
323@@ -21,6 +22,7 @@
324 atexit.register(cleanup)
325
326 def cleanup():
327+ '''Cleanup the program on close.'''
328 events.broadcast('got_shutdown')
329 threadmanager.killall()
330 threadmanager.close_sockets()
331@@ -28,6 +30,7 @@
332 config.save()
333
334 def main():
335+ '''The main program. Parse command line arguments and run.'''
336 print globals['anon+']['banner'] % (globals['anon+']['VERSION'],
337 globals['anon+']['BUILD'])
338 print("== Warning! ==")

Subscribers

People subscribed via source and target branches

to all changes: