예제 #1
0
 def __init__(self, manager):
     super(Node, self).__init__()
     self.id = None
     self.manager = manager
     self.host = get_ip_address()
     self.port = 0
     self.bridge = None
     self.model = None
     self.dataset_path = ""
     self.local_model = None
     self.V = {}
     self.current_round = 0
     self.current_exec = None
     self.start_train = False
     self.neighbors_ids = []
     self.neighbors = []
     self.clustered = None
     self.similarity = []
     self.train = None
     self.val = None
     self.test = None
     self.inference = None
     self.terminate = False
     self.params = Map()
     self.conn_attempts = 0
     # initialize network
     self._init_server()
예제 #2
0
def report_cooldown(form, submit):
    ip = sha256(get_ip_address().encode('utf-8')).hexdigest()
    reports = Report.query.filter(Report.ip == ip,
                                  Report.dismissed == False).order_by(
                                      Report.date.desc()).limit(4)
    counter = 0
    for report in reports:
        if datetime.utcnow() - report.date < timedelta(minutes=5):
            counter += 1
        if counter > 2:
            raise ValidationError('Wait before submitting more reports')
예제 #3
0
 def __init__(self,
              k,
              model,
              data,
              neighbors_ids,
              clustered,
              similarity,
              args: Map,
              params=None):
     super(Node, self).__init__()
     self.id = k
     self.mp = bool(args.mp)
     self.host = get_ip_address()
     self.port = PORT + k
     self.device = args.device
     self.model = model
     self.local_model = model
     self.optimizer = None
     self.grads = None
     self.V = {}
     self.current_round = 0
     self.current_exec = None
     self.neighbors_ids = neighbors_ids
     self.neighbors = []
     self.in_neighbors = []
     self.clustered = clustered
     self.similarity = similarity
     self.train = data.get('train', None)
     self.val = data.get('val', None)
     self.test = data.get('test', None)
     self.inference = data.get('inference', None)
     self.terminate = False
     # default params
     self.params = Map({
         'frac': args.frac,
         'epochs': args.epochs,
         'batch_size': args.batch_size,
         'lr': args.lr,
         'momentum': args.momentum,
         'opt_func': optimizer_func(args.optimizer),
         'gar': args.gar,
         'D': sum(self.similarity.values()),
         'confidence': 1,
         'alpha': 0.9,
     })
     # override params if provided
     if isinstance(params, Map):
         self.params = Map(dict(self.params, **params))
     # initialize networks
     self._init_server()
예제 #4
0
 def __init__(self, nb_devices: int, args: Map, rand_ids=False):
     super(Bridge, self).__init__()
     self.nb_devices = nb_devices
     if rand_ids:
         self.devices_ids = np.random.choice(range(args.num_users), nb_devices, replace=False)
     else:
         self.devices_ids = np.arange(nb_devices)
     self.ids = self.devices_ids.tolist()
     self.args = args
     self.terminate = False
     self.host = get_ip_address()
     self.port = conf.LAUNCHER_PORT
     self.bridges = []
     self.waiting = {}
     self._init_server()
예제 #5
0
def test_tap_data_shape():
    """
    Test the Tap data shape is as expected.
    """
    # src.utils gets run before we can mock it
    # So run get_ip_address() again to set it here
    src.runner.IP_ADDRESS = get_ip_address()
    lens_uid = 'abcdef123456'
    tap_manager = TapManager()
    tap = tap_manager.create_tap(lens_uid)
    assert tap['lens']['uid'] == lens_uid
    assert tap['tap_datetime']
    assert tap['label'] == '1'
    assert tap['data']['lens_reader']['device_name'] == 'DD-00'
    assert tap['data']['lens_reader']['mac_address']
    assert tap['data']['lens_reader']['reader_ip'] == '10.1.2.3'
    assert tap['data']['lens_reader']['reader_model'] == 'IDTech Kiosk IV'
예제 #6
0
def report(post_num):
    post = Post.query.get_or_404(post_num)
    form = ReportForm()
    if form.validate_on_submit():
        ip = sha256(get_ip_address().encode('utf-8')).hexdigest()
        report = Report(ip=ip,
                        reason=form.reason.data,
                        token=form.csrf_token.data,
                        post=post)
        db.session.add(report)
        db.session.commit()

        flash(f'Post #{post.post_num} reported')
        return redirect(url_for('thread', thread_num=post.thread.thread_num))
    return render_template('report_form.html',
                           post=post,
                           form=form,
                           title='Report')
예제 #7
0
def test_get_ip_address_from_balena_fails_gracefully():
    """
    Test get_ip_address from the Balena supervisor API fails gracefully.
    """
    ip_address = get_ip_address()
    assert not ip_address
예제 #8
0
def test_get_ip_address_from_balena():
    """
    Test get_ip_address from the Balena supervisor API works as expected.
    """
    ip_address = get_ip_address()
    assert ip_address == '10.1.2.3'