Пример #1
0
def main():
    signal.signal(signal.SIGINT, handler)
    signal.signal(signal.SIGTERM, handler)

    parse_arguments()

    logging.basicConfig(level=shared.log_level,
                        format='[%(asctime)s] [%(levelname)s] %(message)s')
    logging.info('Starting MiNode')

    logging.info('Data directory: {}'.format(shared.data_directory))
    if not os.path.exists(shared.data_directory):
        try:
            os.makedirs(shared.data_directory)
        except Exception as e:
            logging.warning(
                'Error while creating data directory in: {}'.format(
                    shared.data_directory))
            logging.warning(e)

    load_data()

    if shared.ip_enabled and not shared.trusted_peer:
        bootstrap_from_dns()

    if shared.i2p_enabled:
        # We are starting it before cleaning expired objects so we can collect I2P destination objects
        start_i2p_listener()

    for vector in set(shared.objects):
        if not shared.objects[vector].is_valid():
            if shared.objects[vector].is_expired():
                logging.debug('Deleted expired object: {}'.format(
                    base64.b16encode(vector).decode()))
            else:
                logging.warning('Deleted invalid object: {}'.format(
                    base64.b16encode(vector).decode()))
            del shared.objects[vector]

    manager = Manager()
    manager.start()

    advertiser = Advertiser()
    advertiser.start()

    if shared.listen_for_connections:
        start_ip_listener()
Пример #2
0
def main():
    signal.signal(signal.SIGINT, handler)
    signal.signal(signal.SIGTERM, handler)
    logging.basicConfig(level=shared.log_level,
                        format='[%(asctime)s] [%(levelname)s] %(message)s')
    logging.info('Starting MiNode')
    if not os.path.exists(shared.data_directory):
        try:
            os.makedirs(shared.data_directory)
        except Exception as e:
            logging.warning(
                'Error while creating data directory in: {}'.format(
                    shared.data_directory))
            logging.warning(e)
    try:
        with open(shared.data_directory + 'objects.pickle', mode='br') as file:
            shared.objects = pickle.load(file)
    except Exception as e:
        logging.warning('Error while loading objects from disk.')
        logging.warning(e)

    try:
        with open(shared.data_directory + 'nodes.pickle', mode='br') as file:
            shared.node_pool = pickle.load(file)
    except Exception as e:
        logging.warning('Error while loading nodes from disk.')
        logging.warning(e)

    with open(os.path.join(shared.source_directory, 'core_nodes.csv'),
              mode='r',
              newline='') as f:
        reader = csv.reader(f)
        shared.core_nodes = {tuple(row) for row in reader}
        shared.node_pool.update(shared.core_nodes)

    if not shared.trusted_peer:
        try:
            for item in socket.getaddrinfo('bootstrap8080.bitmessage.org', 80):
                shared.unchecked_node_pool.add((item[4][0], 8080))
                logging.debug(
                    'Adding ' + item[4][0] +
                    ' to unchecked_node_pool based on DNS bootstrap method')
            for item in socket.getaddrinfo('bootstrap8444.bitmessage.org', 80):
                shared.unchecked_node_pool.add((item[4][0], 8444))
                logging.debug(
                    'Adding ' + item[4][0] +
                    ' to unchecked_node_pool based on DNS bootstrap method')
        except Exception as e:
            logging.error('Error during DNS bootstrap')
            logging.error(e)

    manager = Manager()
    manager.clean_objects()
    manager.clean_connections()
    manager.start()

    advertiser = Advertiser()
    advertiser.start()

    listener_ipv4 = None
    listener_ipv6 = None

    if shared.listen_for_connections:
        if socket.has_ipv6:
            try:
                listener_ipv6 = Listener('',
                                         shared.listening_port,
                                         family=socket.AF_INET6)
                listener_ipv6.start()
            except Exception as e:
                logging.warning('Error while starting IPv6 listener')
                logging.warning(e)

        try:
            listener_ipv4 = Listener('', shared.listening_port)
            listener_ipv4.start()
        except Exception as e:
            if listener_ipv6:
                logging.warning(
                    'Error while starting IPv4 listener. '
                    'However the IPv6 one seems to be working and will probably accept IPv4 connections.'
                )
            else:
                logging.error(
                    'Error while starting IPv4 listener.'
                    'You will not receive incoming connections. Please check your port configuration'
                )
                logging.error(e)
Пример #3
0
from advertiser import Advertiser
from operator import itemgetter

#np.random.seed(0)

# creating players
num_creators = 15
num_advertisers = 10
num_viewers = 40

creators = [Creator(i, 5, 1000) for i in range(num_creators)]
creators[0].max_p = 30
creators[1].max_p = 20
creators[2].max_p = 8
advertisers = [
    Advertiser(i, 1000, num_creators) for i in range(num_advertisers)
]
viewers = [Viewer(i, 100, num_creators) for i in range(num_viewers)]

rounds = 20
prev_bids = None
prev_prices = [None] * num_creators

creator_values = [[i] for i in range(num_creators)]
advertiser_values = [[i] for i in range(num_advertisers)]
viewer_values = [[i] for i in range(num_viewers)]

for c in creators:
    creator_values[c.id].append(c.approx_val(prev_bids, advertisers))

for a in advertisers:
Пример #4
0
from baseAdvertising import BaseAdvertising
from ad import Ad
from advertiser import Advertiser

baseAdvertising = BaseAdvertising()
advertiser1 = Advertiser(1, "name1")
advertiser2 = Advertiser(2, "name2")
ad1 = Ad(1, "title1", "img-url1", "link1", advertiser1)
ad2 = Ad(2, "title2", "img-url2", "link2", advertiser2)
print(baseAdvertising.describe_me())
print(ad2.describe_me())
print(advertiser1.describe_me())
ad1.inc_views()
ad1.inc_views()
ad1.inc_views()
ad1.inc_views()
ad2.inc_views()
ad1.inc_clicks()
ad1.inc_clicks()
ad2.inc_clicks()
print(advertiser2.name)
advertiser2.name = "new name"
print(advertiser2.name)
print(ad1.clicks)
print(advertiser2.clicks)
print(Advertiser.get_total_clicks())
print(Advertiser.help())
Пример #5
0
from base_model import BaseAdvertising
from ad import Ad
from advertiser import Advertiser

if __name__ == "__main__":
    baseAdvertising = BaseAdvertising()
    advertiser1 = Advertiser('name1')
    advertiser2 = Advertiser('name2')
    ad1 = Ad("title1", "img-url1", "link1", advertiser1)
    ad2 = Ad("title2", "img-url2", "link2", advertiser2)
    baseAdvertising.describeMe()
    ad2.describeMe()
    advertiser1.describeMe()
    ad1.incViews()
    ad1.incViews()
    ad1.incViews()
    ad1.incViews()
    ad2.incViews()
    ad1.incClicks()
    ad1.incClicks()
    ad2.incClicks()
    advertiser2.getName()
    advertiser2.setName("new name")
    advertiser2.getName()
    ad1.getClicks()
    advertiser2.getClicks()
    Advertiser.getTotalClicks()
    Advertiser.help()