WIP CI Build Errors (#76)

* ignore TODO and kademlia

* remove unnecessary pass

* fixed swarm warnings

* fixed peerdata_interface warnings

* fixed peer warnings

* fixed rest of linting errors

* trying to fix last error

* fixed dup errors
This commit is contained in:
ZX 2018-11-26 18:24:29 -05:00 committed by Alex Haynes
parent 8326f87835
commit 8bcffb67cb
30 changed files with 39 additions and 96 deletions

View File

@ -198,8 +198,7 @@ spelling-store-unknown-words=no
# List of note tags to take in consideration, separated by a comma.
notes=FIXME,
XXX,
TODO
XXX
[TYPECHECK]
@ -326,10 +325,10 @@ ignore-comments=yes
ignore-docstrings=yes
# Ignore imports when computing similarities.
ignore-imports=no
ignore-imports=yes
# Minimum lines number of a similarity.
min-similarity-lines=4
min-similarity-lines=8
[BASIC]

View File

@ -9,7 +9,7 @@ install:
script:
- pytest --cov=./ -v
- pylint --rcfile=.pylintrc encryption host kademlia libp2p network peer stream_muxer transport tests
- pylint --rcfile=.pylintrc encryption host libp2p network peer stream_muxer transport tests
after_success:
- codecov

View File

@ -35,7 +35,6 @@ class BasicHost(IHost):
"""
:return: mux instance of host
"""
pass
def set_stream_handler(self, protocol_id, stream_handler):
"""

View File

@ -8,21 +8,18 @@ class IHost(ABC):
"""
:return: peer_id of host
"""
pass
@abstractmethod
def get_network(self):
"""
:return: network instance of host
"""
pass
@abstractmethod
def get_mux(self):
"""
:return: mux instance of host
"""
pass
@abstractmethod
def set_stream_handler(self, protocol_id, stream_handler):
@ -32,7 +29,6 @@ class IHost(ABC):
:param stream_handler: a stream handler function
:return: true if successful
"""
pass
# protocol_id can be a list of protocol_ids
# stream will decide which protocol_id to run on
@ -43,4 +39,3 @@ class IHost(ABC):
:param proto_id: protocol id that stream runs on
:return: true if successful
"""
pass

View File

@ -2,6 +2,7 @@ from .raw_connection_interface import IRawConnection
class RawConnection(IRawConnection):
# pylint: disable=too-few-public-methods
def __init__(self, ip, port, reader, writer):
self.conn_ip = ip

View File

@ -1,5 +1,6 @@
from abc import ABC
# pylint: disable=too-few-public-methods
class IRawConnection(ABC):
"""

View File

@ -120,4 +120,3 @@ class MultiAddr:
class MultiAddrValueError(ValueError):
"""Raised when the input string to the MultiAddr constructor was invalid."""
pass

View File

@ -8,7 +8,6 @@ class INetwork(ABC):
"""
:return: the peer id
"""
pass
@abstractmethod
def set_stream_handler(self, protocol_id, stream_handler):
@ -17,7 +16,6 @@ class INetwork(ABC):
:param stream_handler: a stream handler instance
:return: true if successful
"""
pass
@abstractmethod
def new_stream(self, peer_id, protocol_id):
@ -26,7 +24,6 @@ class INetwork(ABC):
:param protocol_id: protocol id
:return: stream instance
"""
pass
@abstractmethod
def listen(self, *args):
@ -34,4 +31,3 @@ class INetwork(ABC):
:param *args: one or many multiaddrs to start listening on
:return: True if at least one success
"""
pass

View File

@ -1,6 +1,5 @@
from abc import ABC, abstractmethod
class INetStream(ABC):
@abstractmethod
@ -8,7 +7,6 @@ class INetStream(ABC):
"""
:return: protocol id that stream runs on
"""
pass
@abstractmethod
def set_protocol(self, protocol_id):
@ -16,28 +14,24 @@ class INetStream(ABC):
:param protocol_id: protocol id that stream runs on
:return: true if successful
"""
pass
@abstractmethod
def read(self):
"""
read from stream
reads from the underlying muxed_stream
:return: bytes of input
"""
pass
@abstractmethod
def write(self, _bytes):
"""
write to stream
write to the underlying muxed_stream
:return: number of bytes written
"""
pass
@abstractmethod
def close(self):
"""
close stream
close the underlying muxed stream
:return: true if successful
"""
pass

View File

@ -1,16 +1,15 @@
import uuid
from peer.id import ID
from .network_interface import INetwork
from .stream.net_stream import NetStream
from .multiaddr import MultiAddr
from .connection.raw_connection import RawConnection
from peer.id import ID
class Swarm(INetwork):
# pylint: disable=too-many-instance-attributes, cell-var-from-loop
def __init__(self, my_peer_id, peerstore, upgrader):
self._my_peer_id = my_peer_id
self.id = ID(my_peer_id)
self.self_id = ID(my_peer_id)
self.peerstore = peerstore
self.upgrader = upgrader
self.connections = dict()
@ -19,7 +18,7 @@ class Swarm(INetwork):
self.transport = None
def get_peer_id(self):
return self.id
return self.self_id
def set_stream_handler(self, protocol_id, stream_handler):
"""
@ -94,7 +93,7 @@ class Swarm(INetwork):
multiaddr_dict['port'], reader, writer)
muxed_conn = self.upgrader.upgrade_connection(raw_conn, False)
muxed_stream, stream_id, protocol_id = await muxed_conn.accept_stream()
muxed_stream, _, protocol_id = await muxed_conn.accept_stream()
net_stream = NetStream(muxed_stream)
net_stream.set_protocol(protocol_id)
@ -106,7 +105,7 @@ class Swarm(INetwork):
try:
# Success
listener = self.transport.create_listener(conn_handler)
self.listeners[multiaddr_str] = listener
self.listeners[multiaddr_str] = listener
await listener.listen(multiaddr)
return True
except IOError:

View File

@ -13,7 +13,6 @@ class IAddrBook(ABC):
:param addr: multiaddress of the peer
:param ttl: time-to-live for the address (after this time, address is no longer valid)
"""
pass
@abstractmethod
def add_addrs(self, peer_id, addrs, ttl):
@ -25,7 +24,6 @@ class IAddrBook(ABC):
:param addr: multiaddresses of the peer
:param ttl: time-to-live for the address (after this time, address is no longer valid
"""
pass
@abstractmethod
def addrs(self, peer_id):
@ -33,7 +31,6 @@ class IAddrBook(ABC):
:param peer_id: peer to get addresses of
:return: all known (and valid) addresses for the given peer
"""
pass
@abstractmethod
def clear_addrs(self, peer_id):
@ -41,12 +38,10 @@ class IAddrBook(ABC):
Removes all previously stored addresses
:param peer_id: peer to remove addresses of
"""
pass
@abstractmethod
def peers_with_addrs(self):
"""
:return: all of the peer IDs stored with addresses
"""
pass

View File

@ -14,4 +14,4 @@ class ID:
return "<peer.ID %s>" % pid
return "<peer.ID %s*%s>" % (pid[:2], pid[len(pid)-6:])
__repr__ = __str__
__repr__ = __str__

View File

@ -31,9 +31,7 @@ class PeerData(IPeerData):
def get_metadata(self, key):
if key in self.metadata:
return self.metadata[key]
else:
raise PeerDataError("key not found")
raise PeerDataError("key not found")
class PeerDataError(KeyError):
"""Raised when a key is not found in peer metadata"""
pass

View File

@ -7,42 +7,36 @@ class IPeerData(ABC):
"""
:return: all protocols associated with given peer
"""
pass
@abstractmethod
def add_protocols(self, protocols):
"""
:param protocols: protocols to add
"""
pass
@abstractmethod
def set_protocols(self, protocols):
"""
:param protocols: protocols to add
"""
pass
@abstractmethod
def add_addrs(self, addrs):
"""
:param addrs: multiaddresses to add
"""
pass
@abstractmethod
def get_addrs(self):
"""
:return: all multiaddresses
"""
pass
@abstractmethod
def clear_addrs(self):
"""
Clear all addresses
"""
pass
@abstractmethod
def put_metadata(self, key, val):
@ -51,7 +45,6 @@ class IPeerData(ABC):
:param val: val to associate with key
:raise Exception: unsuccesful put
"""
pass
@abstractmethod
def get_metadata(self, key):
@ -60,4 +53,3 @@ class IPeerData(ABC):
:return: val for key
:raise Exception: key not found
"""
pass

View File

@ -1,4 +1,5 @@
class PeerInfo:
# pylint: disable=too-few-public-methods
def __init__(self, peer_id, peer_data):
self.peer_id = peer_id
self.addrs = peer_data.get_addrs()

View File

@ -13,7 +13,6 @@ class IPeerMetadata(ABC):
:return: value at key for given peer
:raise Exception: peer ID not found
"""
pass
@abstractmethod
def put(self, peer_id, key, val):
@ -23,5 +22,4 @@ class IPeerMetadata(ABC):
:param val: value to associated with key
:raise Exception: unsuccessful put
"""
pass

View File

@ -31,8 +31,7 @@ class PeerStore(IPeerStore):
def get_protocols(self, peer_id):
if peer_id in self.peer_map:
return self.peer_map[peer_id].get_protocols()
else:
raise PeerStoreError("peer ID not found")
raise PeerStoreError("peer ID not found")
def add_protocols(self, peer_id, protocols):
peer = self.__create_or_get_peer(peer_id)
@ -49,8 +48,7 @@ class PeerStore(IPeerStore):
if peer_id in self.peer_map:
val = self.peer_map[peer_id].get_metadata(key)
return val
else:
raise PeerStoreError("peer ID not found")
raise PeerStoreError("peer ID not found")
def put(self, peer_id, key, val):
# <<?>>
@ -69,8 +67,7 @@ class PeerStore(IPeerStore):
def addrs(self, peer_id):
if peer_id in self.peer_map:
return self.peer_map[peer_id].get_addrs()
else:
raise PeerStoreError("peer ID not found")
raise PeerStoreError("peer ID not found")
def clear_addrs(self, peer_id):
# Only clear addresses if the peer is in peer map
@ -88,4 +85,3 @@ class PeerStore(IPeerStore):
class PeerStoreError(KeyError):
"""Raised when peer ID is not found in peer store"""
pass

View File

@ -1,4 +1,4 @@
from abc import ABC, abstractmethod
from abc import abstractmethod
from .addrbook_interface import IAddrBook
from .peermetadata_interface import IPeerMetadata
@ -14,7 +14,6 @@ class IPeerStore(IAddrBook, IPeerMetadata):
:param peer_id: peer ID to get info for
:return: peer info object
"""
pass
@abstractmethod
def get_protocols(self, peer_id):
@ -23,7 +22,6 @@ class IPeerStore(IAddrBook, IPeerMetadata):
:return: protocols (as strings)
:raise Exception: peer ID not found exception
"""
pass
@abstractmethod
def add_protocols(self, peer_id, protocols):
@ -32,7 +30,6 @@ class IPeerStore(IAddrBook, IPeerMetadata):
:param protocols: protocols to add
:raise Exception: peer ID not found
"""
pass
@abstractmethod
def set_protocols(self, peer_id, protocols):
@ -41,11 +38,9 @@ class IPeerStore(IAddrBook, IPeerMetadata):
:param protocols: protocols to set
:raise Exception: peer ID not found
"""
pass
@abstractmethod
def peers(self):
"""
:return: all of the peer IDs stored in peer store
"""
pass

View File

@ -45,7 +45,6 @@ class Mplex(IMuxedConn):
check connection is fully closed
:return: true if successful
"""
pass
async def read_buffer(self, stream_id):
# Empty buffer or nonexistent stream
@ -119,7 +118,8 @@ class Mplex(IMuxedConn):
message = data[end_index:end_index + length + 1]
# Deal with other types of messages
flag = header & 0x07
# TODO use flag
# flag = header & 0x07
stream_id = header >> 3
if stream_id not in self.buffers:

View File

@ -4,6 +4,7 @@ from ..muxed_stream_interface import IMuxedStream
class MplexStream(IMuxedStream):
# pylint: disable=too-many-instance-attributes
"""
reference: https://github.com/libp2p/go-mplex/blob/master/stream.go
"""

View File

@ -12,7 +12,6 @@ class IMuxedConn(ABC):
close connection
:return: true if successful
"""
pass
@abstractmethod
def is_closed(self):
@ -20,7 +19,6 @@ class IMuxedConn(ABC):
check connection is fully closed
:return: true if successful
"""
pass
@abstractmethod
def open_stream(self, protocol_id, peer_id, multi_addr):
@ -32,7 +30,6 @@ class IMuxedConn(ABC):
:param multi_addr: multi_addr that stream connects to
:return: a new stream
"""
pass
@abstractmethod
def accept_stream(self):
@ -40,4 +37,3 @@ class IMuxedConn(ABC):
accepts a muxed stream opened by the other end
:return: the accepted stream
"""
pass

View File

@ -1,31 +1,27 @@
from abc import ABC, abstractmethod
class IMuxedStream(ABC):
@abstractmethod
def read(self):
"""
read from stream
reads from the underlying muxed_conn
:return: bytes of input
"""
pass
@abstractmethod
def write(self, _bytes):
"""
write to stream
writes to the underlying muxed_conn
:return: number of bytes written
"""
pass
@abstractmethod
def close(self):
"""
close stream
close the underlying muxed_conn
:return: true if successful
"""
pass
@abstractmethod
def reset(self):
@ -34,7 +30,6 @@ class IMuxedStream(ABC):
tells this remote side to hang up
:return: error/exception
"""
pass
@abstractmethod
def set_deadline(self, ttl):
@ -42,4 +37,3 @@ class IMuxedStream(ABC):
set deadline for muxed stream
:return: a new stream
"""
pass

View File

@ -1,11 +1,11 @@
import pytest
from libp2p.libp2p import *
from libp2p.libp2p import new_node
@pytest.mark.asyncio
async def test_simple_messages():
hostA = await new_node(transport_opt=["/ip4/127.0.0.1/tcp/8001/ipfs/hostA"])
hostB = await new_node(transport_opt=["/ip4/127.0.0.1/tcp/8000/ipfs/hostB"])
node_a = await new_node(transport_opt=["/ip4/127.0.0.1/tcp/8001/ipfs/node_a"])
node_b = await new_node(transport_opt=["/ip4/127.0.0.1/tcp/8000/ipfs/node_b"])
async def stream_handler(stream):
while True:
@ -16,12 +16,12 @@ async def test_simple_messages():
print("sending response:" + response)
await stream.write(response.encode())
hostB.set_stream_handler("/echo/1.0.0", stream_handler)
node_b.set_stream_handler("/echo/1.0.0", stream_handler)
# Associate the peer with local ip address (see default parameters of Libp2p())
hostA.get_peerstore().add_addr("hostB", "/ip4/127.0.0.1/tcp/8000", 10)
node_a.get_peerstore().add_addr("node_b", "/ip4/127.0.0.1/tcp/8000", 10)
stream = await hostA.new_stream("hostB", "/echo/1.0.0")
stream = await node_a.new_stream("node_b", "/echo/1.0.0")
messages = ["hello" + str(x) for x in range(10)]
for message in messages:

View File

@ -12,7 +12,8 @@ async def handle_echo(reader, writer):
writer.close()
@pytest.mark.asyncio
# TODO: this test should develop out into a fuller test between MPlex modules communicating with each other.
# TODO: this test should develop out into a fuller test between MPlex
# modules communicating with each other.
async def test_simple_echo():
server_ip = '127.0.0.1'
server_port = 8888

View File

@ -5,7 +5,6 @@ from peer.peerstore import PeerStore
# Testing methods from IPeerMetadata base class.
def test_get_empty():
with pytest.raises(PeerStoreError):
store = PeerStore()

View File

@ -1,6 +1,3 @@
import pytest
from peer.peerstore import PeerStoreError
from peer.peerstore import PeerStore
# Testing methods from IPeerStore base class.

View File

@ -1,5 +1,7 @@
import pytest
# pylint: disable=eval-used
@pytest.mark.parametrize("test_input,expected", [
("3+5", 8),
("2+4", 6),

View File

@ -10,7 +10,6 @@ class IListener(ABC):
:param multiaddr: multiaddr of peer
:return: return True if successful
"""
pass
@abstractmethod
def get_addrs(self):
@ -18,7 +17,6 @@ class IListener(ABC):
retrieve list of addresses the listener is listening on
:return: return list of addrs
"""
pass
@abstractmethod
def close(self, options=None):
@ -29,4 +27,3 @@ class IListener(ABC):
a timeout value in ms that fires and destroy all connections
:return: return True if successful
"""
pass

View File

@ -11,7 +11,6 @@ class ITransport(ABC):
:param options: optional object
:return: list of multiaddrs
"""
pass
@abstractmethod
def create_listener(self, handler_function, options=None):
@ -22,4 +21,3 @@ class ITransport(ABC):
that takes a connection as argument which implements interface-connection
:return: a listener object that implements listener_interface.py
"""
pass

View File

@ -2,6 +2,7 @@ from stream_muxer.mplex.mplex import Mplex
class TransportUpgrader():
# pylint: disable=no-self-use
def __init__(self, secOpt, muxerOpt):
self.sec = secOpt
@ -12,7 +13,6 @@ class TransportUpgrader():
upgrade multiaddr listeners to libp2p-transport listeners
"""
pass
def upgrade_security(self):
pass