Beispiel #1
0
 def get_attributes(self, locations):
     outgoing_beacons = []
     for beacon in self.db.get_beacons():
         beacon_str = beacon.to_bech32_str()
         outgoing_beacons.append(beacon_str)
     incoming_beacons = []
     for shared_seed in self.db.get_shared_seeds():
         beacon = MoneysocketBeacon(shared_seed)
         for location in locations:
             beacon.add_location(location)
         beacon_str = beacon.to_bech32_str()
         incoming_beacons.append(beacon_str)
     connection_attempts = {
         b: str(ca)
         for b, ca in self.connection_attempts.items()
     }
     info = {
         'name': self.db.get_name(),
         'wad': self.db.get_wad(),
         'cap': self.db.get_cap(),
         'outgoing_beacons': outgoing_beacons,
         'incoming_beacons': incoming_beacons,
         'connection_attempts': connection_attempts
     }
     return info
Beispiel #2
0
    def listen(self, args):
        name = args.account
        account = self.directory.lookup_by_name(name)
        if not account:
            return "*** unknown account: %s" % name

        shared_seed_str = args.shared_seed
        if shared_seed_str:
            shared_seed = SharedSeed.from_hex_str(shared_seed_str)
            if not shared_seed:
                return ("*** could not understand shared seed: %s" %
                        args.shared_seed)
            beacon = MoneysocketBeacon(shared_seed)
        else:
            # generate a shared_seed
            beacon = MoneysocketBeacon()
            shared_seed = beacon.shared_seed

        # generate new beacon
        # location is the terminus_stack's incoming websocket
        beacon.locations = self.terminus_stack.get_listen_locations()
        account.add_shared_seed(shared_seed)
        # register shared seed with local listener
        self.terminus_stack.local_connect(shared_seed)
        self.directory.reindex_account(account)
        return "listening: %s to %s" % (name, beacon)
Beispiel #3
0
def generate_beacon(account):
    beacon = MoneysocketBeacon()
    location = WebsocketLocation(config['Beacon']['RelayLocation'])
    beacon.add_location(location)
    info = connect_rpc(account, str(beacon))
    if not info['success']:
        return render_accounts(error=info['error'])
    return render_accounts()
Beispiel #4
0
 def iter_summary_lines(self, locations):
     yield "\t%s: wad: %s " % (self.db.get_name(), self.db.get_wad())
     for beacon in self.db.get_beacons():
         beacon_str = beacon.to_bech32_str()
         yield "\t\toutgoing beacon: %s" % beacon_str
         ca = (self.connection_attempts[beacon_str]
               if beacon_str in self.connection_attempts else "(none)")
         yield "\t\t\tconnection attempt: %s" % str(ca)
     for shared_seed in self.db.get_shared_seeds():
         beacon = MoneysocketBeacon(shared_seed)
         for location in locations:
             beacon.add_location(location)
         yield "\t\tincoming shared seed: %s" % str(shared_seed)
         yield "\t\t\tincoming beacon: %s" % beacon.to_bech32_str()
Beispiel #5
0
    def connect(self, args):
        name = args.account
        account = self.directory.lookup_by_name(name)
        if not account:
            return {
                'success': False,
                'error': "*** unknown account: %s" % name
            }

        beacon_str = args.beacon
        beacon, err = MoneysocketBeacon.from_bech32_str(beacon_str)
        if err:
            return {
                'success': False,
                'error': "*** could not decode beacon: %s" % err
            }
        location = beacon.locations[0]
        if location.to_dict()['type'] != "WebSocket":
            return {
                'success': False,
                'error': "*** can't connect to beacon location"
            }
        if len(account.get_beacons()) == MAX_BEACONS:
            return {
                'success': False,
                'error': "*** max %s beacons per account" % MAX_BEACONS
            }

        shared_seed = beacon.shared_seed
        connection_attempt = self.provider_stack.connect(location, shared_seed)
        account.add_connection_attempt(beacon, connection_attempt)
        account.add_beacon(beacon)
        self.directory.reindex_account(account)
        return {'success': True, "name": name, "location": str(location)}
Beispiel #6
0
 def __init__(self):
     self.beacon, _ = MoneysocketBeacon.from_bech32_str(BEACON)
     self.provider_layer = ProviderLayer(self, self)
     self.rendezvous_layer = OutgoingRendezvousLayer(self,
                                                     self.provider_layer)
     self.websocket_layer = OutgoingWebsocketLayer(self,
                                                   self.rendezvous_layer)
     self.provider_ss = None
     self.ready = False
Beispiel #7
0
    def connectasset(self, parsed):
        print("app connect asset")
        beacon, err = MoneysocketBeacon.from_bech32_str(parsed.beacon)
        if err:
            return err

        self.connect_db.add_beacon(beacon)
        connection_attempt = self.consumer_stack.do_connect(beacon)
        self.asset_pool.add_connection_attempt(beacon, connection_attempt)
        return "connected"
Beispiel #8
0
def test_beacon(beacon):
    print(json.dumps(beacon.to_dict(), indent=1))
    b32 = beacon.to_bech32_str()
    print("")
    print(b32)
    print("")
    print(b32.upper())
    print("")
    beacon2, err = MoneysocketBeacon.from_bech32_str(b32)
    print("err: %s" % err)
    print(json.dumps(beacon2.to_dict(), indent=1))
    print("\n")
Beispiel #9
0
 def disconnectasset(self, parsed):
     print("app disconnect asset")
     beacon, err = MoneysocketBeacon.from_bech32_str(parsed.beacon)
     if err:
         return err
     if not self.connect_db.has_beacon(beacon):
         return "beacon not known"
     self.connect_db.remove_beacon(beacon)
     self.asset_pool.remove_connection_attempt(beacon)
     # TODO - don't disconnect everything
     self.consumer_stack.do_disconnect()
     return "disconnected"
Beispiel #10
0
    def connect(self, args):
        name = args.account
        account = self.directory.lookup_by_name(name)
        if not account:
            return "*** unknown account: %s" % name

        beacon_str = args.beacon

        beacon, err = MoneysocketBeacon.from_bech32_str(beacon_str)
        if err:
            return "*** could not decode beacon: %s" % err
        location = beacon.locations[0]
        if location.to_dict()['type'] != "WebSocket":
            return "*** can't connect to beacon location"

        shared_seed = beacon.shared_seed
        connection_attempt = self.terminus_stack.connect(location, shared_seed)
        account.add_connection_attempt(beacon, connection_attempt)
        account.add_beacon(beacon)
        self.directory.reindex_account(account)
        return "connected: %s to %s" % (name, str(location))
Beispiel #11
0
    def listen(self, args):
        name = args.account
        account = self.directory.lookup_by_name(name)
        if not account:
            return {
                'success': False,
                'error': "*** unknown account: %s" % name
            }

        shared_seed_str = args.shared_seed
        if shared_seed_str:
            shared_seed = SharedSeed.from_hex_str(shared_seed_str)
            if not shared_seed:
                return {
                    'success':
                    False,
                    'error': ("*** could not understand shared seed: %s" %
                              args.shared_seed)
                }
            beacon = MoneysocketBeacon(shared_seed)
        else:
            # generate a shared_seed
            beacon = MoneysocketBeacon()
            shared_seed = beacon.shared_seed

        # generate new beacon
        # location is the provider_stack's incoming websocket
        beacon.locations = self.provider_stack.get_listen_locations()
        account.add_shared_seed(shared_seed)
        # register shared seed with local listener
        self.provider_stack.local_connect(shared_seed)
        self.set_local_seed_connecting(shared_seed)
        self.directory.reindex_account(account)
        return {
            'success': True,
            "name": name,
            "beacon": beacon.to_bech32_str()
        }
Beispiel #12
0
 def get_asset_beacons(self):
     return [
         MoneysocketBeacon.from_bech32_str(b)[0]
         for b in self.db['asset_beacons']
     ]
Beispiel #13
0
 def iter_beacons(self):
     for b in self.db['beacons']:
         yield MoneysocketBeacon.from_bech32_str(b)[0]
Beispiel #14
0
    print(json.dumps(beacon.to_dict(), indent=1))
    b32 = beacon.to_bech32_str()
    print("")
    print(b32)
    print("")
    print(b32.upper())
    print("")
    beacon2, err = MoneysocketBeacon.from_bech32_str(b32)
    print("err: %s" % err)
    print(json.dumps(beacon2.to_dict(), indent=1))
    print("\n")


ss = SharedSeed()

b1 = MoneysocketBeacon(shared_seed=ss)
b1.add_location(WebsocketLocation("relay.socket.money"))
b1.add_location(WebRtcLocation())
b1.add_location(BluetoothLocation())
b1.add_location(NfcLocation())

test_beacon(b1)

b2 = MoneysocketBeacon(shared_seed=ss)
b2.add_location(WebsocketLocation("relay.socket.money"))

test_beacon(b2)

b3 = MoneysocketBeacon(shared_seed=ss)
b3.add_location(
    WebsocketLocation("relay.socket.money", use_tls=False, port=666))
Beispiel #15
0
 def get_disconnected_beacons(self):
     dbs = []
     for beacon_str, connection_attempt in self.connection_attempts.items():
         if connection_attempt.get_state() == "disconnected":
             dbs.append(MoneysocketBeacon.from_bech32_str(beacon_str)[0])
     return dbs