From 301837931186ccb1f5e0af0fb5d632199bff5b77 Mon Sep 17 00:00:00 2001 From: Cort Buffington Date: Thu, 21 Jul 2016 12:41:36 -0500 Subject: [PATCH] move config file to SAMPLE --- hblink.cfg => hblink-SAMPLE.cfg | 4 ++-- hblink.py | 31 +++++++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 4 deletions(-) rename hblink.cfg => hblink-SAMPLE.cfg (95%) diff --git a/hblink.cfg b/hblink-SAMPLE.cfg similarity index 95% rename from hblink.cfg rename to hblink-SAMPLE.cfg index f755360..3e58ba3 100644 --- a/hblink.cfg +++ b/hblink-SAMPLE.cfg @@ -16,7 +16,7 @@ PASSPHRASE: s3cr37w0rd [MASTER-2] MODE: MASTER -ENABLED: True +ENABLED: False IP: PORT: 55000 PASSPHRASE: 13370p3r470r @@ -46,7 +46,7 @@ PACKAGE_ID: HBlink v1.0 [REPEATER-2] MODE: CLIENT -ENABLED: True +ENABLED: False IP: PORT: 54002 MASTER_IP: 172.16.1.1 diff --git a/hblink.py b/hblink.py index 7d1bfac..947a7d2 100755 --- a/hblink.py +++ b/hblink.py @@ -16,11 +16,15 @@ import os # Specifig functions from modules we need from binascii import b2a_hex as h from socket import gethostbyname +from random import randint + +# Debugging functions from pprint import pprint # Twisted is pretty important, so I keep it separate from twisted.internet.protocol import DatagramProtocol from twisted.internet import reactor +from twisted.internet import task # Other files we pull from -- this is mostly for readability and segmentation import hb_log @@ -72,11 +76,34 @@ logger.debug('Logging system started, anything from here on gets logged') class HBMASTER(DatagramProtocol): def __init__(self, *args, **kwargs): pass + + def startProtocol(self): + pass + + class HBCLIENT(DatagramProtocol): def __init__(self, *args, **kwargs): - pass - + if len(args) == 1: + self._client = args[0] + self._config = CONFIG['CLIENTS'][self._client] + else: + # If we didn't get called correctly, log it! + logger.error('(%s) HBCLIENT was not called with an argument. Terminating', self._client) + sys.exit() + + def startProtocol(self): + + # Set up periodic loop for sending pings to the master. Run every minute + self._peer_maintenance = task.LoopingCall(self.peer_maintenance_loop) + self._peer_maintenance_loop = self._peer_maintenance.start(60) + + def peer_maintenance_loop(self): + ###### Need to add check to see if the peer is connected, and only do this if it is. + logger.debug('(%s) Sending ping to Master', self._client) + + def datagramReceived(self, data, (host, port)): + print(data) #************************************************