Esempio n. 1
0
        public TranslationTester()
        {
            localGateway = new APITranslationServer(server, new IPEndPoint(IPAddress.Loopback, 12000), api);
            running      = localGateway.Run();
            var args = new APITranslatorClient.ConnectionArgs {
                Address = IPAddress.Loopback, Port = 12000, Self = client, ServerID = server.ID
            };

            remoteGateway = APITranslatorClient.CreateAndConnect(args).Result;
        }
Esempio n. 2
0
        public async void OnConnect(string folder, IPEndPoint endpoint)
        {
            var             file = Path.Combine(folder, "client.identity");
            PrivateIdentity identity;

            if (!Env.CheckFile(file))
            {
                if (!Env.Confirm($"No identity was found at {file}. Do you want to create a new one?"))
                {
                    return;
                }
                identity = PrivateIdentity.Create();
                var hex = Transcoder.HexFromBytes(PrivateIdentity.Export(identity));
                await Env.WriteFile(file, hex);
            }
            else
            {
                var hex    = Transcoder.BytesFromHex(await Env.ReadFile(file));
                var result = PrivateIdentity.Import(hex);
                if (result.IsError)
                {
                    Env.Alert("Could not load identity!!");
                    return;
                }
                identity = result.Value;
            }

            APITranslatorClient nodeConnection;

            try
            {
                nodeConnection = await APITranslatorClient.CreateAndConnect(new APITranslatorClient.ConnectionArgs
                {
                    Self     = identity,
                    ServerID = identity.ID,
                    Address  = endpoint.Address,
                    Port     = endpoint.Port
                });
            }
            catch
            {
                Env.Alert("Unable to connect to your node!");
                return;
            }

            Resources = new ResourceManager(identity, nodeConnection, OnDisconnect);
            VM        = new ConnectedViewModel(OnDisconnect);
        }
Esempio n. 3
0
        private async Task <APITranslatorClient?> AddIfValid(Address address, bool inform = false)
        {
            APITranslatorClient messenger;

            try
            {
                messenger = await APITranslatorClient.CreateAndConnect(new APITranslatorClient.ConnectionArgs
                {
                    Address  = IPAddress.Parse(address.IP),
                    Port     = address.Port,
                    ServerID = address.UserID,
                    Self     = self
                });
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
                return(null);
            }

            if (inform)
            {
                try
                {
                    await messenger.InformAddress(port);
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e);
                }
            }

            await conn.InsertOrReplaceAsync(address);

            return(messenger);
        }