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