Beispiel #1
0
        private void NewConnectionEstablished(AddressIdentifier clientAddress, ConnectionSessionId newSessionId)
        {
            sessionRepository.AddSession(newSessionId, TimeTools.GetCurrentTimeStamp().Item2, clientAddress, false);

            heartbeatThreadCollection.AddThread(clientAddress, newSessionId);
            notificationThreadCollection.AddThread(clientAddress, newSessionId);
        }
Beispiel #2
0
        private async void DoConnect()
        {
            if (AddressIdentifier.IsIpAddressIdentifier(ServerAddress))
            {
                session.TryConnect(new Address(Protocol, AddressIdentifier.GetIpAddressIdentifierFromString(ServerAddress)),
                                   new Address(Protocol, AddressIdentifier.GetIpAddressIdentifierFromString(ClientAddress)),
                                   errorMessage =>
                {
                    Application.Current.Dispatcher.Invoke(async() =>
                    {
                        var dialog = new UserDialogBox(
                            "",
                            $"Es kann keine Verbindung mit {ServerAddress} hergestellt werden",
                            MessageBoxButton.OK
                            );
                        await dialog.ShowMahAppsDialog();
                    });
                });
            }
            else
            {
                var dialog = new UserDialogBox("", $"{ServerAddress} ist keine gültige Ip-Adresse",
                                               MessageBoxButton.OK);
                await dialog.ShowMahAppsDialog();
            }

            SetAutoConnectToSettings();
        }
Beispiel #3
0
 public bool IsClientAddressConnected(AddressIdentifier clientAddress)
 {
     lock (currentSessions)
     {
         return(currentSessions.Values.Any(sessionInfo => sessionInfo.ClientAddress == clientAddress));
     }
 }
 public BeginConnectionRequestHandler(Action <ConnectionSessionId> connectionSuccessfulCallback,
                                      AddressIdentifier clientAddress,
                                      Action <string> errorCallback)
     : base(errorCallback)
 {
     this.clientAddress = clientAddress;
     this.connectionSuccessfulCallback = connectionSuccessfulCallback;
 }
Beispiel #5
0
        public void AddThread(AddressIdentifier clientAddressIdentifier, ConnectionSessionId id)
        {
            var clientAddress   = new Address(new TcpIpProtocol(), clientAddressIdentifier);
            var heartbeatThread = new HeartbeatThread(clientAddress, id);

            heartbeatThreads.Add(id, heartbeatThread);
            heartbeatThread.ClientVanished += HeartbeatOnClientVanished;
            new Thread(heartbeatThread.Run).Start();
        }
Beispiel #6
0
        private bool IsConnectPossible()
        {
            if (ServerAddress == null)
            {
                return(false);
            }

            return(AddressIdentifier.IsIpAddressIdentifier(ServerAddress) &&
                   session.CurrentApplicationState == ApplicationState.DisconnectedFromServer);
        }
        protected void AddTentative(byte[] obj, AddressIdentifier address)
        {
            if (!this.tentative.TryGetValue(obj, out HashSet <AddressIdentifier> addresses))
            {
                addresses           = new HashSet <AddressIdentifier>();
                this.tentative[obj] = addresses;
            }

            addresses.Add(address);
        }
Beispiel #8
0
 public SessionInfo(ConnectionSessionId sessionId, Time creationTime,
                    AddressIdentifier clientAddress, bool isDebugConnection,
                    User loggedInUser = null)
 {
     SessionId         = sessionId;
     CreationTime      = creationTime;
     ClientAddress     = clientAddress;
     IsDebugConnection = isDebugConnection;
     LoggedInUser      = loggedInUser;
 }
Beispiel #9
0
        public void AddSession(ConnectionSessionId sessionId, Time creationTime,
                               AddressIdentifier clientAddress, bool isDebugConnection)
        {
            lock (currentSessions)
            {
                var newSessionInfo = new SessionInfo(sessionId, creationTime, clientAddress, isDebugConnection);
                currentSessions.Add(sessionId, newSessionInfo);

                NewSessionStarted?.Invoke(newSessionInfo);
            }
        }
Beispiel #10
0
        public void AddThread(AddressIdentifier clientAddressIdentifier, ConnectionSessionId id)
        {
            var clientAddress      = new Address(new TcpIpProtocol(), clientAddressIdentifier);
            var notificationQueue  = new TimeoutBlockingQueue <NotificationObject>(1000);
            var notificationThread = new NotificationThread(zmqContext, clientAddress, id, notificationQueue);

            notificationThreads.Add(id, notificationThread);
            notificationQueues.Add(id, notificationQueue);

            new Thread(notificationThread.Run).Start();
        }
 public LocalSettingsData(bool isAutoConnectionEnabled,
                          AddressIdentifier autoConnectionClientAddress,
                          AddressIdentifier autoConnectionServerAddress,
                          Guid lastUsedMedicalPracticeId,
                          Guid lastLoggedInUserId)
 {
     IsAutoConnectionEnabled     = isAutoConnectionEnabled;
     AutoConnectionClientAddress = autoConnectionClientAddress;
     AutoConnectionServerAddress = autoConnectionServerAddress;
     LastUsedMedicalPracticeId   = lastUsedMedicalPracticeId;
     LastLoggedInUserId          = lastLoggedInUserId;
 }
        public override ITopUpTracker GetTopUpTracker(AddressIdentifier address)
        {
            var key = new TopUpTracker(this.processBlocksInfo, address.WalletId, (int)address.AccountIndex, (int)address.AddressType);

            if (!this.processBlocksInfo.Trackers.TryGetValue(key, out TopUpTracker tracker))
            {
                tracker = key;
                tracker.ReadAccount();
                this.processBlocksInfo.Trackers.Add(tracker, tracker);
            }

            return(tracker);
        }
Beispiel #13
0
 private void SetAutoConnectToSettings()
 {
     if (AutoConnectOnNextStart)
     {
         localSettingsRepository.IsAutoConnectionEnabled     = true;
         localSettingsRepository.AutoConnectionServerAddress = AddressIdentifier.GetIpAddressIdentifierFromString(ServerAddress);
         localSettingsRepository.AutoConnectionClientAddress = AddressIdentifier.GetIpAddressIdentifierFromString(ClientAddress);
     }
     else
     {
         localSettingsRepository.IsAutoConnectionEnabled     = false;
         localSettingsRepository.AutoConnectionClientAddress = new IpV4AddressIdentifier(127, 0, 0, 1);
         localSettingsRepository.AutoConnectionServerAddress = new IpV4AddressIdentifier(127, 0, 0, 1);
     }
 }
        /// <inheritdoc />
        public bool Contains(Script scriptPubKey, out AddressIdentifier address)
        {
            address = null;

            var res = base.Contains(scriptPubKey.ToBytes(), out HashSet <AddressIdentifier> addresses);

            if (res != null)
            {
                if ((bool)res)
                {
                    address = addresses.First();
                }

                return((bool)res);
            }

            return(Exists(scriptPubKey, out address));
        }
Beispiel #15
0
        public static IReadOnlyList <Address> GetAllAvailableLocalIpAddresses()
        {
            var hostName    = Dns.GetHostName();
            var addressList = new List <Address>();
            var protocol    = new TcpIpProtocol();

            Dns.GetHostEntry(hostName).AddressList
            .Select(address => address.ToString())
            .Where(AddressIdentifier.IsIpAddressIdentifier)
            .Select(address => new Address(protocol, AddressIdentifier.GetIpAddressIdentifierFromString(address)))
            .Do(addressList.Add);

            if (addressList.Count == 0)
            {
                addressList.Add(new Address(protocol, new IpV4AddressIdentifier(127, 0, 0, 1)));
            }

            return(addressList);
        }
        private bool Exists(Script scriptPubKey, out AddressIdentifier address)
        {
            string hex = scriptPubKey.ToHex();

            address = this.conn.FindWithQuery <AddressIdentifier>($@"
                        SELECT  WalletId
                        ,       AccountIndex
                        ,       AddressType
                        ,       AddressIndex
                        ,       ScriptPubKey
                        FROM    HDAddress
                        WHERE   ScriptPubKey = '{hex}' {
                    // Restrict to wallet if provided.
                    // "BETWEEN" boosts performance from half a seconds to 2ms.
                    ((this.walletId != null) ? $@"
                        AND     WalletId BETWEEN {this.walletId} AND {this.walletId}" : "")};");

            return(address != null);
        }
Beispiel #17
0
 public BeginConnectionRequest(AddressIdentifier clientAddress)
     : base(NetworkMessageType.BeginConnectionRequest)
 {
     ClientAddress = clientAddress;
 }
 private void DoActivateConnection()
 {
     ActiveConnection = SelectedIpAddress;
     connectionService.InitiateCommunication(new Address(new TcpIpProtocol(),
                                                         AddressIdentifier.GetIpAddressIdentifierFromString(SelectedIpAddress)));
 }
Beispiel #19
0
        public LocalSettingsData Load()
        {
            if (!File.Exists(filename))
            {
                return(LocalSettingsData.CreateDefaultSettings());
            }

            bool isAutoConnectionEnabled = false;
            AddressIdentifier autoConnectionClientAddress = new IpV4AddressIdentifier(127, 0, 0, 1);
            AddressIdentifier autoConnectionServerAddress = new IpV4AddressIdentifier(127, 0, 0, 1);
            Guid lastUsedMedicalPracticeId = Guid.Empty;
            Guid lastLoggedInUserId        = Guid.Empty;

            var reader = XmlReader.Create(filename);

            while (reader.Read())
            {
                if (reader.NodeType != XmlNodeType.Element || reader.Name != XmlRoot)
                {
                    continue;
                }

                while (reader.Read())
                {
                    if (reader.NodeType != XmlNodeType.Element)
                    {
                        continue;
                    }

                    switch (reader.Name)
                    {
                    case AutoConnection:
                    {
                        while (reader.MoveToNextAttribute())
                        {
                            switch (reader.Name)
                            {
                            case IsAutoConnectionEnabledAttribute:     isAutoConnectionEnabled = bool.Parse(reader.Value); break;

                            case AutoConnectionClientAddressAttribute: autoConnectionClientAddress = AddressIdentifier.GetIpAddressIdentifierFromString(reader.Value); break;

                            case AutoConnectionServerAddressAttribute: autoConnectionServerAddress = AddressIdentifier.GetIpAddressIdentifierFromString(reader.Value); break;
                            }
                        }
                        break;
                    }

                    case LastSession:
                    {
                        while (reader.MoveToNextAttribute())
                        {
                            switch (reader.Name)
                            {
                            case LastUsedMedicalPracticeIdAttribute: lastUsedMedicalPracticeId = Guid.Parse(reader.Value); break;

                            case LastLoggedInUserIdAttribute:                lastLoggedInUserId = Guid.Parse(reader.Value); break;
                            }
                        }
                        break;
                    }
                    }
                }
            }
            reader.Close();

            return(new LocalSettingsData(isAutoConnectionEnabled,
                                         autoConnectionClientAddress,
                                         autoConnectionServerAddress,
                                         lastUsedMedicalPracticeId,
                                         lastLoggedInUserId));
        }
 /// <inheritdoc />
 public void AddTentative(Script scriptPubKey, AddressIdentifier address)
 {
     base.AddTentative(scriptPubKey.ToBytes(), address);
 }
 /// <inheritdoc />
 public void AddTentative(OutPoint outPoint, AddressIdentifier address)
 {
     base.AddTentative(outPoint.ToBytes(), address);
 }
Beispiel #22
0
 public Address(Protocol protocol, AddressIdentifier identifier)
 {
     Protocol   = protocol;
     Identifier = identifier;
 }
Beispiel #23
0
        public static BeginConnectionRequest Parse(string s)
        {
            var clientAddress = AddressIdentifier.GetIpAddressIdentifierFromString(s);

            return(new BeginConnectionRequest(clientAddress));
        }
Beispiel #24
0
        private void NewDebugConnectionEstablishedCallback(AddressIdentifier clientAddress, ConnectionSessionId newSessionId)
        {
            sessionRepository.AddSession(newSessionId, TimeTools.GetCurrentTimeStamp().Item2, clientAddress, true);

            notificationThreadCollection.AddThread(clientAddress, newSessionId);
        }