-
Notifications
You must be signed in to change notification settings - Fork 1
/
run_publisher.py
41 lines (37 loc) · 1.37 KB
/
run_publisher.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import uuid
import yaml
import os
from dandelion import Publisher
if __name__ == '__main__':
ROOT_DIR = os.environ["ROOT_DIR"] = os.path.dirname(__file__)
f = open(os.path.join(ROOT_DIR, "config.yaml"), "r")
config = yaml.safe_load(f)
try:
base_dir = config["BASE_DIRECTORY"]
except KeyError:
base_dir = "/tmp"
id = ''
try:
f = open(os.path.join(base_dir, "publisher-id.txt"), "r")
id = f.read()
f.close()
except IOError:
pass
if not id or "publisher-" not in id:
id = "publisher-" + uuid.uuid4().hex
f = open(os.path.join(base_dir, "publisher-id.txt"), "w")
f.write(id)
f.close()
print("Your ID: %s" % id)
redis_address = (config["REDIS_HOST"], config["REDIS_PORT"])
publisher = Publisher(id,
ip=config["PUBLISHER_IP"],
entrance_urls=config["ENTRANCE_URLS"],
min_http_peers=config["MIN_HTTP_PEERS"],
redis_address=redis_address,
redis_db=config["DB"],
redis_maxsize=config["PUBLISHER_REDIS_MAXSIZE"],
redis_minsize=config["PUBLISHER_REDIS_MINSIZE"],
ping_entrance_freq=config["PUBLISHER_PING_ENTRANCE_FREQ"]
)
publisher.start()