Add basic docstrings
This commit is contained in:
parent
5a4d6b686e
commit
e95f2b522a
|
@ -1,3 +1,6 @@
|
||||||
|
"""
|
||||||
|
Advertiser thread advertises new addresses and objects among all connections
|
||||||
|
"""
|
||||||
import logging
|
import logging
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
|
@ -6,6 +9,7 @@ from . import message, shared
|
||||||
|
|
||||||
|
|
||||||
class Advertiser(threading.Thread):
|
class Advertiser(threading.Thread):
|
||||||
|
"""The advertiser thread"""
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__(name='Advertiser')
|
super().__init__(name='Advertiser')
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
"""The logic and behaviour of a single connection"""
|
||||||
import base64
|
import base64
|
||||||
import errno
|
import errno
|
||||||
import logging
|
import logging
|
||||||
|
@ -14,6 +15,7 @@ from . import message, shared, structure
|
||||||
|
|
||||||
|
|
||||||
class Connection(threading.Thread):
|
class Connection(threading.Thread):
|
||||||
|
"""The connection object"""
|
||||||
def __init__(
|
def __init__(
|
||||||
self, host, port, s=None, network='ip', server=False,
|
self, host, port, s=None, network='ip', server=False,
|
||||||
i2p_remote_dest=b''
|
i2p_remote_dest=b''
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
"""A package for working with I2P"""
|
||||||
from .controller import I2PController
|
from .controller import I2PController
|
||||||
from .dialer import I2PDialer
|
from .dialer import I2PDialer
|
||||||
from .listener import I2PListener
|
from .listener import I2PListener
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
"""Listener thread creates connection objects for incoming connections"""
|
||||||
import logging
|
import logging
|
||||||
import socket
|
import socket
|
||||||
import threading
|
import threading
|
||||||
|
@ -8,6 +9,7 @@ from .connection import Connection
|
||||||
|
|
||||||
|
|
||||||
class Listener(threading.Thread):
|
class Listener(threading.Thread):
|
||||||
|
"""The listener thread"""
|
||||||
def __init__(self, host, port, family=socket.AF_INET):
|
def __init__(self, host, port, family=socket.AF_INET):
|
||||||
super().__init__(name='Listener')
|
super().__init__(name='Listener')
|
||||||
self.host = host
|
self.host = host
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
"""Functions for starting the program"""
|
||||||
import argparse
|
import argparse
|
||||||
import base64
|
import base64
|
||||||
import csv
|
import csv
|
||||||
|
@ -16,11 +17,13 @@ from .listener import Listener
|
||||||
|
|
||||||
|
|
||||||
def handler(s, f): # pylint: disable=unused-argument
|
def handler(s, f): # pylint: disable=unused-argument
|
||||||
|
"""Signal handler"""
|
||||||
logging.info('Gracefully shutting down MiNode')
|
logging.info('Gracefully shutting down MiNode')
|
||||||
shared.shutting_down = True
|
shared.shutting_down = True
|
||||||
|
|
||||||
|
|
||||||
def parse_arguments():
|
def parse_arguments():
|
||||||
|
"""Parsing arguments"""
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument('-p', '--port', help='Port to listen on', type=int)
|
parser.add_argument('-p', '--port', help='Port to listen on', type=int)
|
||||||
parser.add_argument('--host', help='Listening host')
|
parser.add_argument('--host', help='Listening host')
|
||||||
|
@ -100,6 +103,7 @@ def parse_arguments():
|
||||||
|
|
||||||
|
|
||||||
def load_data():
|
def load_data():
|
||||||
|
"""Loads initial nodes and data, stored in files between sessions"""
|
||||||
try:
|
try:
|
||||||
with open(
|
with open(
|
||||||
os.path.join(shared.data_directory, 'objects.pickle'), 'br'
|
os.path.join(shared.data_directory, 'objects.pickle'), 'br'
|
||||||
|
@ -149,6 +153,7 @@ def load_data():
|
||||||
|
|
||||||
|
|
||||||
def bootstrap_from_dns():
|
def bootstrap_from_dns():
|
||||||
|
"""Addes addresses of bootstrap servers to known nodes"""
|
||||||
try:
|
try:
|
||||||
for item in socket.getaddrinfo('bootstrap8080.bitmessage.org', 80):
|
for item in socket.getaddrinfo('bootstrap8080.bitmessage.org', 80):
|
||||||
shared.unchecked_node_pool.add((item[4][0], 8080))
|
shared.unchecked_node_pool.add((item[4][0], 8080))
|
||||||
|
@ -165,6 +170,7 @@ def bootstrap_from_dns():
|
||||||
|
|
||||||
|
|
||||||
def start_ip_listener():
|
def start_ip_listener():
|
||||||
|
"""Starts `.listener.Listener`"""
|
||||||
listener_ipv4 = None
|
listener_ipv4 = None
|
||||||
listener_ipv6 = None
|
listener_ipv6 = None
|
||||||
|
|
||||||
|
@ -201,6 +207,7 @@ def start_ip_listener():
|
||||||
|
|
||||||
|
|
||||||
def start_i2p_listener():
|
def start_i2p_listener():
|
||||||
|
"""Starts I2P threads"""
|
||||||
# Grab I2P destinations from old object file
|
# Grab I2P destinations from old object file
|
||||||
for obj in shared.objects.values():
|
for obj in shared.objects.values():
|
||||||
if obj.object_type == shared.i2p_dest_obj_type:
|
if obj.object_type == shared.i2p_dest_obj_type:
|
||||||
|
@ -263,6 +270,7 @@ def start_i2p_listener():
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
"""Script entry point"""
|
||||||
signal.signal(signal.SIGINT, handler)
|
signal.signal(signal.SIGINT, handler)
|
||||||
signal.signal(signal.SIGTERM, handler)
|
signal.signal(signal.SIGTERM, handler)
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
"""The main thread, managing connections, nodes and objects"""
|
||||||
import base64
|
import base64
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
@ -14,6 +15,7 @@ from .i2p import I2PDialer
|
||||||
|
|
||||||
|
|
||||||
class Manager(threading.Thread):
|
class Manager(threading.Thread):
|
||||||
|
"""The manager thread"""
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__(name='Manager')
|
super().__init__(name='Manager')
|
||||||
self.q = queue.Queue()
|
self.q = queue.Queue()
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
"""Protocol message objects"""
|
||||||
import base64
|
import base64
|
||||||
import hashlib
|
import hashlib
|
||||||
import struct
|
import struct
|
||||||
|
@ -8,6 +9,7 @@ from . import shared, structure
|
||||||
|
|
||||||
|
|
||||||
class Header():
|
class Header():
|
||||||
|
"""Common message header"""
|
||||||
def __init__(self, command, payload_length, payload_checksum):
|
def __init__(self, command, payload_length, payload_checksum):
|
||||||
self.command = command
|
self.command = command
|
||||||
self.payload_length = payload_length
|
self.payload_length = payload_length
|
||||||
|
@ -43,6 +45,7 @@ class Header():
|
||||||
|
|
||||||
|
|
||||||
class Message():
|
class Message():
|
||||||
|
"""Common message structure"""
|
||||||
def __init__(self, command, payload):
|
def __init__(self, command, payload):
|
||||||
self.command = command
|
self.command = command
|
||||||
self.payload = payload
|
self.payload = payload
|
||||||
|
@ -85,6 +88,7 @@ class Message():
|
||||||
|
|
||||||
|
|
||||||
class Version():
|
class Version():
|
||||||
|
"""The version message"""
|
||||||
def __init__(
|
def __init__(
|
||||||
self, host, port, protocol_version=shared.protocol_version,
|
self, host, port, protocol_version=shared.protocol_version,
|
||||||
services=shared.services, nonce=shared.nonce,
|
services=shared.services, nonce=shared.nonce,
|
||||||
|
@ -155,6 +159,7 @@ class Version():
|
||||||
|
|
||||||
|
|
||||||
class Inv():
|
class Inv():
|
||||||
|
"""The inv message"""
|
||||||
def __init__(self, vectors):
|
def __init__(self, vectors):
|
||||||
self.vectors = set(vectors)
|
self.vectors = set(vectors)
|
||||||
|
|
||||||
|
@ -190,6 +195,7 @@ class Inv():
|
||||||
|
|
||||||
|
|
||||||
class GetData():
|
class GetData():
|
||||||
|
"""The getdata message"""
|
||||||
def __init__(self, vectors):
|
def __init__(self, vectors):
|
||||||
self.vectors = set(vectors)
|
self.vectors = set(vectors)
|
||||||
|
|
||||||
|
@ -225,6 +231,7 @@ class GetData():
|
||||||
|
|
||||||
|
|
||||||
class Addr():
|
class Addr():
|
||||||
|
"""The addr message"""
|
||||||
def __init__(self, addresses):
|
def __init__(self, addresses):
|
||||||
self.addresses = addresses
|
self.addresses = addresses
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
"""Doing proof of work"""
|
||||||
import base64
|
import base64
|
||||||
import hashlib
|
import hashlib
|
||||||
import logging
|
import logging
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
"""Common variables and structures, referred in different threads"""
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import queue
|
import queue
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
"""Protocol structures"""
|
||||||
import base64
|
import base64
|
||||||
import hashlib
|
import hashlib
|
||||||
import logging
|
import logging
|
||||||
|
@ -10,6 +11,7 @@ from . import shared
|
||||||
|
|
||||||
|
|
||||||
class VarInt():
|
class VarInt():
|
||||||
|
"""varint object"""
|
||||||
def __init__(self, n):
|
def __init__(self, n):
|
||||||
self.n = n
|
self.n = n
|
||||||
|
|
||||||
|
@ -44,6 +46,7 @@ class VarInt():
|
||||||
|
|
||||||
|
|
||||||
class Object():
|
class Object():
|
||||||
|
"""object message"""
|
||||||
def __init__(
|
def __init__(
|
||||||
self, nonce, expires_time, object_type, version,
|
self, nonce, expires_time, object_type, version,
|
||||||
stream_number, object_payload
|
stream_number, object_payload
|
||||||
|
@ -139,6 +142,7 @@ class Object():
|
||||||
|
|
||||||
|
|
||||||
class NetAddrNoPrefix():
|
class NetAddrNoPrefix():
|
||||||
|
"""Network address"""
|
||||||
def __init__(self, services, host, port):
|
def __init__(self, services, host, port):
|
||||||
self.services = services
|
self.services = services
|
||||||
self.host = host
|
self.host = host
|
||||||
|
@ -171,6 +175,7 @@ class NetAddrNoPrefix():
|
||||||
|
|
||||||
|
|
||||||
class NetAddr():
|
class NetAddr():
|
||||||
|
"""Network address with time and stream"""
|
||||||
def __init__(self, services, host, port, stream=shared.stream):
|
def __init__(self, services, host, port, stream=shared.stream):
|
||||||
self.stream = stream
|
self.stream = stream
|
||||||
self.services = services
|
self.services = services
|
||||||
|
|
Loading…
Reference in New Issue
Block a user