示例#1
0
 public static void Initialize(string keyPass)
 {
     VerificationKeyProvider.Initialize(KeyFile, keyPass);
     Initialization.Run();
     foreach (var t in ConnectionTargets)
     {
         try
         {
             new ErebusLink(TCPIPConnectionUtils.Connect(t.Item1, t.Item2), Instance, false);
         }
         catch (Exception e)
         {
             Log.RecordEvent(typeof(App), $"Failed to connect to {t.Item1}:{t.Item2}: {e.Message}", LogEntrySeverity.Error);
         }
     }
     btConnListener = new BluetoothConnectionListener(Instance);
     btReqListener  = new BluetoothContactRequestListener(Instance.Address, (addr, name) =>
     {
         if (Current.Dispatcher.Invoke(() => MessageBox.Show(Current.MainWindow, "Would you like to accept this request?", $"Received contact request via Bluetooth from {name}", MessageBoxButton.YesNo)) == MessageBoxResult.Yes)
         {
             Current.Dispatcher.Invoke(() => (Current.MainWindow as MainWindow).Navigate(new Uri("/Views/AddContact.xaml", UriKind.Relative), new { Address = addr, Name = $"Bluetooth device '{name}'" }));
             return(true);
         }
         return(false);
     });
     Task.Run(usersUpdateProcess);
     Task.Run(onlineUpdateProcess);
 }
示例#2
0
        static void Main(string[] args)
        {
            Log.EntryRecorded += (sender, e) => Console.WriteLine($"{sender} ({e.Severity}): {e.Message}");
            VerificationKeyProvider.Initialize("keyinfo.dat", "hello world");
            var vkp = new VerificationKeyProvider();

            Initialization.Run();
            SSMP ssmp = null;

            SSMP.InvitationReceived += (sender, e) =>
            {
                if (ssmp == null)
                {
                    ssmp = e.Accept();
                }
                ssmp.MessageReceived  += Ssmp_MessageReceived;
                ssmp.ConnectionClosed += (_sender, _e) => ssmp = null;
            };
            var ei = new ErebusInstance(new ErebusAddress(Console.ReadLine()));

            ei.Services = new[] { HDPService.SSMP };
            var l = new TCPIPConnectionListener(int.Parse(Console.ReadLine()), ei);

            while (true)
            {
                try
                {
                    var cmd = Console.ReadLine().Split(' ');
                    switch (cmd[0])
                    {
                    case "addlink":
                        new ErebusLink(TCPIPConnectionUtils.Connect(cmd[1], int.Parse(cmd[2])), ei, false);
                        break;

                    case "listlink":
                        foreach (var link in ei.Links)
                        {
                            Console.WriteLine(link.RemoteAddress);
                        }
                        break;

                    case "hdp":
                        var hdp = new HDP(ei, HDPService.SSMP);
                        hdp.SendRequest(ErebusAddress.Broadcast);
                        hdp.InitClose();
                        break;

                    case "ssmp":
                        ssmp = new SSMP(ei, new ErebusAddress(cmd[1]));
                        ssmp.MessageReceived += Ssmp_MessageReceived;
                        break;

                    case "msg":
                        ssmp?.SendMessage(cmd.Skip(1).Aggregate((x, y) => x + " " + y));
                        break;

                    case "addkey":
                        var addr = new ErebusAddress(cmd[1]);
                        vkp.RemoveKeyPair(addr);
                        var key = vkp.CreatePrivateKey();
                        Console.WriteLine("Key: " + key.Item2.Select(x => x.ToString()).Aggregate((x, y) => x + "," + y));
                        Console.Write("Please copy other key to clipboard, then press <enter> . . .");
                        Console.ReadLine();
                        vkp.AddKeyPair(addr, key.Item1, Clipboard.GetText().Split(',').Select(x => byte.Parse(x)).ToArray());
                        break;

                    case "removekey":
                        vkp.RemoveKeyPair(new ErebusAddress(cmd[1]));
                        break;

                    case "close":
                        ssmp?.Dispose();
                        ssmp = null;
                        break;

                    case "exit":
                        return;
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }
        }