Skip to content

Commit

Permalink
Line Ending PEP8 Errors
Browse files Browse the repository at this point in the history
  • Loading branch information
super3 committed Jan 18, 2016
1 parent e78aea7 commit da14e05
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 24 deletions.
5 changes: 3 additions & 2 deletions pyp2p/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ def int2ip(addr):
def build_bound_socket(source_ip):
def bound_socket(*a, **k):
if source_ip == "127.0.0.1":
raise Exception("This function requires a LAN IP (127.0.0.1 passed.)")
raise Exception("This function requires a LAN IP"
" (127.0.0.1 passed.)")

sock = true_socket(*a, **k)
sock.bind((source_ip, 0))
Expand Down Expand Up @@ -291,7 +292,7 @@ def sequential_bind(n, interface="default"):

def is_port_forwarded(source_ip, port, proto, forwarding_servers):
global true_socket
if source_ip != None:
if source_ip is not None:
socket.socket = build_bound_socket(source_ip)

ret = 0
Expand Down
24 changes: 16 additions & 8 deletions pyp2p/net.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,8 @@ def add_node(self, node_ip, node_port, node_type, timeout=5):
# Check they've started net first
# If they haven't we won't know the NAT details / node type.
if not self.is_net_started:
raise Exception("Make sure to start net before you add node.")
raise Exception("Make sure to start net before you add"
" node.")

if self.nat_type in self.rendezvous.predictable_nats:
# Attempt to make active simultaneous connection.
Expand Down Expand Up @@ -637,7 +638,8 @@ def determine_node(self):
# Check port isn't already forwarded.
if is_port_forwarded(lan_ip, self.passive_port, "TCP",
self.forwarding_servers):
self.debug_print("Port already forwarded. Skipping NAT traversal.")
msg = "Port already forwarded. Skipping NAT traversal."
self.debug_print(msg)

self.forwarding_type = "forwarded"
return "passive"
Expand Down Expand Up @@ -676,7 +678,8 @@ def determine_node(self):
self.debug_print("Port forwarded with NATPMP.")
else:
self.debug_print("Failed to forward port with NATPMP.")
self.debug_print("Falling back on TCP hole punching or proxying.")
self.debug_print("Falling back on TCP hole punching or"
" proxying.")
except Exception as e:
# Log exception
error = parse_exception(e)
Expand Down Expand Up @@ -712,7 +715,8 @@ def start(self):
"""

self.debug_print("Starting networking.")
self.debug_print("Make sure to iterate over replies if you need connection alive management!")
self.debug_print("Make sure to iterate over replies if you need"
" connection alive management!")

# Register a cnt + c handler
signal.signal(signal.SIGINT, self.stop)
Expand Down Expand Up @@ -746,7 +750,8 @@ def start(self):
# is manually specified.
if self.node_type == "simultaneous":
if self.nat_type not in self.rendezvous.predictable_nats:
self.debug_print("Manual setting of simultanous specified but ignored since NAT does not support it.")
self.debug_print("Manual setting of simultanous specified but"
" ignored since NAT does not support it.")
self.node_type = "active"
else:
# Determine node type.
Expand Down Expand Up @@ -1045,7 +1050,8 @@ def synchronize(self):
def success_builder():
def success(con):
# Indicate status.
self.debug_print("Received reverse connect notice")
self.debug_print("Received reverse connect"
" notice")
self.debug_print(nonce)

# Did you send this?
Expand Down Expand Up @@ -1082,7 +1088,8 @@ def success(con):
if their_unl["value"] not in self.unl.pending_reverse_con:
self.debug_print(their_unl)
self.debug_print(str(self.unl.pending_reverse_con))
self.debug_print("oops, we don't know about this reverse query!")
self.debug_print("oops, we don't know about this"
" reverse query!")
processed.append(dht_response)
continue
else:
Expand All @@ -1101,7 +1108,8 @@ def success(con):
pattern = "^REVERSE_ORIGIN:" + reverse_query["unl"]
pattern += "$"
if re.match(pattern, msg) is not None:
self.debug_print("Removing pending reverse query: success!")
self.debug_print("Removing pending reverse"
" query: success!")
self.pending_reverse_queries.remove(
reverse_query)
processed.append(dht_response)
Expand Down
8 changes: 5 additions & 3 deletions pyp2p/rendezvous_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def server_connect(self, sock=None, index=None, servers=None):
)

# Pre-bound socket.
if sock != None:
if sock is not None:
con.set_sock(sock)

# Connect the socket.
Expand Down Expand Up @@ -310,7 +310,8 @@ def predict_mappings(self, mappings):
delta type mapping behaviour.
"""
if self.nat_type not in self.predictable_nats:
raise Exception("Can't predict mappings for non-predictable NAT type.")
msg = "Can't predict mappings for non-predictable NAT type."
raise Exception(msg)

for mapping in mappings:
mapping["bound"] = mapping["sock"].getsockname()[1]
Expand Down Expand Up @@ -700,7 +701,8 @@ def determine_nat(self, return_instantly=1):
# Check collision ration.
if self.port_collisions * 5 > self.nat_tests:
msg = "Port collision number is too high compared to nat tests."
msg += " Collisions must be in ratio 1 : 5 to avoid ambiguity in test results."
msg += " Collisions must be in ratio 1 : 5 to avoid ambiguity"
msg += " in test results."
raise Exception(msg)

# Load mappings for reuse test.
Expand Down
30 changes: 21 additions & 9 deletions pyp2p/rendezvous_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,13 @@ def propogate_candidates(self, node_ip):
continue

# Notify node of challege from client.
msg = "CHALLENGE %s %s %s" % (candidate["ip_addr"], " ".join(map(str, candidate["predictions"])), candidate["proto"])
msg = "CHALLENGE %s %s %s" % (
candidate["ip_addr"],
" ".join(map(str, candidate["predictions"])),
candidate["proto"])

self.factory.nodes["simultaneous"][node_ip]["con"].send_line(msg)
self.factory.nodes["simultaneous"][node_ip]["con"].\
send_line(msg)
old_candidates.append(candidate)

def synchronize_simultaneous(self, node_ip):
Expand All @@ -167,9 +171,12 @@ def synchronize_simultaneous(self, node_ip):
continue

# Synchronise simultaneous node.
if candidate["time"] - self.factory.nodes["simultaneous"][node_ip]["time"] > self.challege_timeout:
if candidate["time"] -\
self.factory.nodes["simultaneous"][node_ip]["time"] >\
self.challege_timeout:
msg = "RECONNECT"
self.factory.nodes["simultaneous"][node_ip]["con"].send_line(msg)
self.factory.nodes["simultaneous"][node_ip]["con"].\
send_line(msg)
return

self.cleanup_candidates(node_ip)
Expand All @@ -185,7 +192,8 @@ def connectionMade(self):
ip_addr = self.transport.getPeer().host
if ip_addr in self.factory.nodes["simultaneous"]:
# Update time.
self.factory.nodes["simultaneous"][ip_addr]["time"] = time.time()
self.factory.nodes["simultaneous"][ip_addr]["time"] =\
time.time()
self.synchronize_simultaneous(ip_addr)
except Exception as e:
error = parse_exception(e)
Expand Down Expand Up @@ -220,7 +228,8 @@ def connectionLost(self, reason):
# Delete old simultaneous nodes.
old_node_ips = []
for node_ip in list(self.factory.nodes["simultaneous"]):
simultaneous_node = self.factory.nodes["simultaneous"][node_ip]
simultaneous_node =\
self.factory.nodes["simultaneous"][node_ip]
# Gives enough time for passive nodes to receive clients.
if t - simultaneous_node["time"] >= self.node_lifetime:
old_node_ips.append(node_ip)
Expand All @@ -244,7 +253,8 @@ def connectionLost(self, reason):
self.factory.candidates[node_ip].remove(candidate)

# Record old node IPs.
if not len(self.factory.candidates[node_ip]) and not node_ip in self.factory.nodes["simultaneous"]:
if not len(self.factory.candidates[node_ip]) and \
not node_ip in self.factory.nodes["simultaneous"]:
old_node_ips.append(node_ip)

# Remove old node IPs.
Expand Down Expand Up @@ -310,7 +320,8 @@ def lineReceived(self, line):
continue

# Append new node.
msg += node_type[0] + ":" + ip_addr + ":" + str(element["port"]) + " "
msg += node_type[0] + ":" + ip_addr + ":"
msg += str(element["port"]) + " "
ip_addr_list.remove(ip_addr)
node_no += 1

Expand Down Expand Up @@ -401,7 +412,8 @@ def lineReceived(self, line):
# Delete candidate if it already exists.
if node_ip in self.factory.candidates:
# Max candidates reached.
if len(self.factory.candidates[node_ip]) >= self.max_candidates:
num_candidates = len(self.factory.candidates[node_ip])
if num_candidates >= self.max_candidates:
print("Candidate max candidates reached.")
break

Expand Down
2 changes: 0 additions & 2 deletions pyp2p/upnp.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,5 +260,3 @@ def forward_port(self, proto, src_port, dest_ip, dest_port=None):
print(UPnP().forward_port("TCP", port, addr))
print(is_port_forwarded(get_lan_ip(), str(port), "TCP", forwarding_servers))
"""


0 comments on commit da14e05

Please sign in to comment.