public async Task TestAgentCloseConnectionWorksForOutgoing()
        {
            var endpoint = "127.0.0.1:9604";

            var myDid = await Signus.CreateAndStoreMyDidAsync(_wallet, "{}");

            var identityJson = string.Format("{{\"did\":\"{0}\", \"pk\":\"{1}\", \"verkey\":\"{2}\", \"endpoint\":\"{3}\"}}",
                                             myDid.Did, myDid.Pk, myDid.VerKey, endpoint);

            await Signus.StoreTheirDidAsync(_wallet, identityJson);

            var activeListener = await AgentListener.ListenAsync(endpoint);

            await activeListener.AddIdentityAsync(_pool, _wallet, myDid.Did);

            await AgentConnection.ConnectAsync(_pool, _wallet, myDid.Did, myDid.Did);

            var connectionEvent = await activeListener.WaitForConnection();

            var serverToClientConnection = connectionEvent.Connection;

            await activeListener.CloseAsync();

            var ex = await Assert.ThrowsExceptionAsync <IndyException>(() =>
                                                                       serverToClientConnection.SendAsync("msg")
                                                                       );

            Assert.AreEqual(ErrorCode.CommonInvalidStructure, ex.ErrorCode);
        }
 public async Task CanDisposeClosedConnection()
 {
     using (var connection = await AgentConnection.ConnectAsync(_pool, _wallet, myDid.Did, myDid.Did))
     {
         await connection.CloseAsync();
     }
 }
Beispiel #3
0
        public async Task TestAgentCloseConnectionWorksForIncoming()
        {
            var endpoint = "127.0.0.1:9613";

            var myDid = await Signus.CreateAndStoreMyDidAsync(wallet, "{}");

            var identityJson = string.Format(AGENT_IDENTITY_JSON_TEMPLATE, myDid.Did, myDid.Pk, myDid.VerKey, endpoint);

            await Signus.StoreTheirDidAsync(wallet, identityJson);

            var activeListener = await AgentListener.ListenAsync(endpoint);

            await activeListener.AddIdentityAsync(pool, wallet, myDid.Did);

            var connection = await AgentConnection.ConnectAsync(pool, wallet, myDid.Did, myDid.Did);

            var connectionEvent = await activeListener.WaitForConnectionAsync();

            var serverToClientConnection = connectionEvent.Connection;

            await serverToClientConnection.CloseAsync();

            var ex = await Assert.ThrowsExceptionAsync <InvalidStructureException>(() =>
                                                                                   serverToClientConnection.SendAsync("msg")
                                                                                   );
        }
        public async Task DisposeCanBeCalledRepeatedly()
        {
            var connection = await AgentConnection.ConnectAsync(_pool, _wallet, myDid.Did, myDid.Did);

            connection.Dispose();
            connection.Dispose();
        }
        public void MergeDataRows(AgentConnection agentConnection, AgentHealthState state, string message)
        {
            if (agentConnection == null || state == null)
            {
                return;
            }

            //Add and update nodes
            var matchingNodes = from DataRow r in DataTable.Rows
                                let nodeInDataTable = (AgentConnection)r["Agent"]
                                                      where nodeInDataTable.Address == agentConnection.Address
                                                      select r;

            if (!matchingNodes.Any())
            {
                object[] rowData = new object[2];

                CreateColumnIfNotExist("Status", "", typeof(Bitmap), 16);
                rowData[DataTable.Columns.IndexOf("Status")] = StatusIconProvider.GrayCircle;

                CreateColumnIfNotExist("Agent", "Agent", typeof(AgentConnection), 60);
                rowData[DataTable.Columns.IndexOf("Agent")] = agentConnection;

                DataTable.Rows.Add(rowData);
            }
        }
Beispiel #6
0
        public Connection()
        {
            var agentConnection = new AgentConnection();
            var loggerFactory   = new LoggerFactory();

            _connection = new Srv.Agent.Command.Common.Connection((IComAgentConfiguration)agentConnection.Agent, loggerFactory);
        }
Beispiel #7
0
 /// <summary>
 /// Initializes a new AgentConnectionEvent.
 /// </summary>
 /// <param name="listener">The listener the connection was established on.</param>
 /// <param name="result">The result of the opening the connection.</param>
 /// <param name="connection">The connection.</param>
 /// <param name="senderDid">The DID of the sender.</param>
 /// <param name="receiverDid">The DID of the receiver.</param>
 internal AgentConnectionEvent(AgentListener listener, ErrorCode result, AgentConnection connection, string senderDid, string receiverDid) :
     base(listener.Handle, result)
 {
     Connection  = connection;
     SenderDid   = senderDid;
     ReceiverDid = receiverDid;
     Listener    = listener;
 }
Beispiel #8
0
        [Ignore] //Wait until proper error is implemented in SDK and handle.
        public async Task CanCloseAfterDispose()
        {
            await PrepareForConnection("127.0.0.1:9618");

            var connection = await AgentConnection.ConnectAsync(pool, wallet, _myDid, _myDid);

            connection.Dispose();
            await connection.CloseAsync();
        }
Beispiel #9
0
        public async Task DisposeCanBeCalledRepeatedly()
        {
            await PrepareForConnection("127.0.0.1:9611");

            var connection = await AgentConnection.ConnectAsync(pool, wallet, _myDid, _myDid);

            connection.Dispose();
            connection.Dispose();
        }
Beispiel #10
0
        public async Task CanDisposeClosedConnection()
        {
            await PrepareForConnection("127.0.0.1:9610");

            using (var connection = await AgentConnection.ConnectAsync(pool, wallet, _myDid, _myDid))
            {
                await connection.CloseAsync();
            }
        }
Beispiel #11
0
        public DispatcherBase(AgentConnection client, double interval)
        {
            Client = client;

            _jobScheduler           = new Timer();
            _jobScheduler.Elapsed  += PerformWork;
            _jobScheduler.AutoReset = true;
            Interval = interval;
        }
        private void NodeDataUpdated(AgentConnection agentConnection, NodeNetwork updatedNodes)
        {
            dataGridViewNodes.UpdateNodes(updatedNodes, clientConnectionManager.Session.Database);

            toolStripStatusLabelDatabase.Text = "DB: " + clientConnectionManager.Session.Database.GetDatabaseFilesystemSize();

            int totalNodes   = managedNodes.Nodes.Count;
            int runningNodes = managedNodes.Nodes.Count(n => n.Value.NodeState.Initialized && n.Value.NodeState.NodeOperationState.State == ProcessState.Running);

            toolStripStatusLabelNodeState.Text = $"Nodes: {runningNodes} / {totalNodes}";
        }
        [Ignore] //Appears endpoint cannot be re-connected to.  Requires further testing.
        public async Task EndpointCanBeReUsedAfterDispose()
        {
            var connection = await AgentConnection.ConnectAsync(_pool, _wallet, myDid.Did, myDid.Did);

            await connection.CloseAsync();

            connection.Dispose();

            using (var newConnection = await AgentConnection.ConnectAsync(_pool, _wallet, myDid.Did, myDid.Did))
            {
            }
        }
        public async Task CanCloseAfterDispose()
        {
            var connection = await AgentConnection.ConnectAsync(_pool, _wallet, myDid.Did, myDid.Did);

            connection.Dispose();

            var ex = await Assert.ThrowsExceptionAsync <IndyException>(() =>
                                                                       connection.CloseAsync()
                                                                       );

            Assert.AreEqual(ErrorCode.CommonInvalidStructure, ex.ErrorCode);
        }
Beispiel #15
0
        public async Task TestAgentConnectWorksForRemoteData()
        {
            var endpoint           = "127.0.0.1:9605";
            var listenerWalletName = "listenerWallet";
            var trusteeWalletName  = "trusteeWallet";

            await Wallet.CreateWalletAsync(_poolName, listenerWalletName, "default", null, null);

            var listenerWallet = await Wallet.OpenWalletAsync(listenerWalletName, null, null);

            await Wallet.CreateWalletAsync(_poolName, trusteeWalletName, "default", null, null);

            var trusteeWallet = await Wallet.OpenWalletAsync(trusteeWalletName, null, null);

            var senderWallet = trusteeWallet;

            var createMyDidResult = await Signus.CreateAndStoreMyDidAsync(listenerWallet, "{}");

            var listenerDid    = createMyDidResult.Did;
            var listenerVerkey = createMyDidResult.VerKey;
            var listenerPk     = createMyDidResult.Pk;

            var trusteeDidJson = "{\"seed\":\"000000000000000000000000Trustee1\"}";

            var trusteeDidResult = await Signus.CreateAndStoreMyDidAsync(trusteeWallet, trusteeDidJson);

            var trusteeDid = trusteeDidResult.Did;
            var senderDid  = trusteeDid;

            var nymRequest = await Ledger.BuildNymRequestAsync(trusteeDid, listenerDid, listenerVerkey, null, null);

            await Ledger.SignAndSubmitRequestAsync(_pool, trusteeWallet, trusteeDid, nymRequest);

            var attribRequest = await Ledger.BuildAttribRequestAsync(listenerDid, listenerDid, null,
                                                                     string.Format("{{\"endpoint\":{{\"ha\":\"{0}\",\"verkey\":\"{1}\"}}}}", endpoint, listenerPk), null);

            await Ledger.SignAndSubmitRequestAsync(_pool, listenerWallet, listenerDid, attribRequest);

            var activeListener = await AgentListener.ListenAsync(endpoint);

            await activeListener.AddIdentityAsync(_pool, listenerWallet, listenerDid);

            await AgentConnection.ConnectAsync(_pool, senderWallet, senderDid, listenerDid);

            await listenerWallet.CloseAsync();

            await Wallet.DeleteWalletAsync(listenerWalletName, null);

            await trusteeWallet.CloseAsync();

            await Wallet.DeleteWalletAsync(trusteeWalletName, null);
        }
Beispiel #16
0
        [Ignore] //Appears endpoint cannot be re-connected to.  Requires further testing.
        public async Task EndpointCanBeReUsedAfterDispose()
        {
            await PrepareForConnection("127.0.0.1:9612");

            var connection = await AgentConnection.ConnectAsync(pool, wallet, _myDid, _myDid);

            await connection.CloseAsync();

            connection.Dispose();

            using (var newConnection = await AgentConnection.ConnectAsync(pool, wallet, _myDid, _myDid))
            {
            }
        }
Beispiel #17
0
        public async Task TestAgentConnectWorksForAllDataInWalletPresent()
        {
            var endpoint = "127.0.0.1:9606";

            var myDidResult = await Signus.CreateAndStoreMyDidAsync(wallet, "{}");

            var identityJson = string.Format(AGENT_IDENTITY_JSON_TEMPLATE, myDidResult.Did, myDidResult.Pk, myDidResult.VerKey, endpoint);
            await Signus.StoreTheirDidAsync(wallet, identityJson);

            var activeListener = await AgentListener.ListenAsync(endpoint);

            await activeListener.AddIdentityAsync(pool, wallet, myDidResult.Did);

            await AgentConnection.ConnectAsync(pool, wallet, myDidResult.Did, myDidResult.Did);
        }
        public void UpdateNodes(AgentConnection agentConnection, AgentHealthState state, string message)
        {
            Mapper.MergeDataRows(agentConnection, state, message);
            Mapper.UpdateDataTable(agentConnection, state, message);
            if (this.DataSource == null)
            {
                ConfigureDataGridView();
            }

            if (SelectedRows.Count > 0)
            {
                DataGridViewRow selectedRow            = SelectedRows[0];
                DataGridViewRowStateChangedEventArgs e = new DataGridViewRowStateChangedEventArgs(selectedRow, DataGridViewElementStates.None);
                this.OnRowStateChanged(selectedRow.Index, e);
            }
        }
Beispiel #19
0
        public async Task TestAgentConnectWorksForAllDataInWalletPresent()
        {
            var endpoint = "127.0.0.1:9606";

            var myDidResult = await Signus.CreateAndStoreMyDidAsync(_wallet, "{}");

            var identityJson = string.Format("{{\"did\":\"{0}\", \"pk\":\"{1}\", \"verkey\":\"{2}\", \"endpoint\":\"{3}\"}}",
                                             myDidResult.Did, myDidResult.Pk, myDidResult.VerKey, endpoint);
            await Signus.StoreTheirDidAsync(_wallet, identityJson);

            var activeListener = await AgentListener.ListenAsync(endpoint);

            await activeListener.AddIdentityAsync(_pool, _wallet, myDidResult.Did);

            await AgentConnection.ConnectAsync(_pool, _wallet, myDidResult.Did, myDidResult.Did);
        }
Beispiel #20
0
    public void run()
    {
        bool               result;
        AgentConnection    agentConnection;
        InstantiateRequest request;

        //simulationState.stdout.Send("CH: entering main loop\n");

        tcpListener.Start();

        while (!quit)
        {
            Thread.Sleep(0);
            tcpClient       = tcpListener.AcceptTcpClient();
            agentConnection = new AgentConnection(simulationState, tcpClient);

            //simulationState.stdout.Send(String.Format("CH: accepted client.\n"));

            if (agentConnection.init())
            {
                agentConnections.Add(agentConnection);

                request = new InstantiateRequest(agentConnection);
                simulationState.instantiateRequests.Send(request);
                // Block until we get the signal that the agent has been instantiated in the simulation.
                // Then, we can start running it's thread and it's perceive-act loop.
                if (instantiationResults.Recv(out result))
                {
                    if (result)
                    {
                        agentConnection.start();
                    }
                    else
                    {
                        Debug.Log("CH Error: instantiation unsuccesful.");
                    }
                }
                else
                {
                    Debug.LogError("CH Error: instantiation empty.");
                }
            }
        }
        //simulationState.stdout.Send("CH: exit main loop.\n");
    }
Beispiel #21
0
        public static void Handle_RelayRegisterResult(AgentConnection con, PacketReader reader)
        {
            var result = reader.ReadBoolean();

            if (result)
            {
                Log.Info("LoginServer successfully installed");
            }
            else
            {
                Log.Info("Some problems are appear while installing LoginServer");
            }

            if (result)
            {
                _mCurrentAgentServer = con;
            }
        }
Beispiel #22
0
        public async Task TestAgentSendWorks()
        {
            var endpoint = "127.0.0.1:9609";

            var myDidResult = await Signus.CreateAndStoreMyDidAsync(_wallet, "{}");

            var identityJson = string.Format("{{\"did\":\"{0}\", \"pk\":\"{1}\", \"verkey\":\"{2}\", \"endpoint\":\"{3}\"}}",
                                             myDidResult.Did, myDidResult.Pk, myDidResult.VerKey, endpoint);
            await Signus.StoreTheirDidAsync(_wallet, identityJson);

            var listener = await AgentListener.ListenAsync(endpoint);

            await listener.AddIdentityAsync(_pool, _wallet, myDidResult.Did);

            var clientConnection = await AgentConnection.ConnectAsync(_pool, _wallet, myDidResult.Did, myDidResult.Did);

            var connectionEvent = await listener.WaitForConnection();

            var serverConnection = connectionEvent.Connection;

            var waitListenerConnectionTask = listener.WaitForConnection(); //Start waiting for additional connections - we'll never get one in this test, however.

            var clientToServerMessage = "msg_from_client";
            var serverToClientMessage = "msg_from_server";

            await clientConnection.SendAsync(clientToServerMessage);

            var waitServerMessageTask = serverConnection.WaitForMessage();

            var completedTask = await Task.WhenAny(waitListenerConnectionTask, waitServerMessageTask); //Wait for either an additional connection or message and proceed when one has arrived.

            Assert.AreEqual(completedTask, waitServerMessageTask);

            var serverMessageEvent = await waitServerMessageTask;

            Assert.AreEqual(clientToServerMessage, serverMessageEvent.Message);

            await serverConnection.SendAsync(serverToClientMessage);

            var clientMessageEvent = await clientConnection.WaitForMessage();

            Assert.AreEqual(serverToClientMessage, clientMessageEvent.Message);
        }
    public void run()
    {
        bool result;
        AgentConnection    agentConnection;
        InstantiateRequest request;

        //simulationState.stdout.Send("CH: entering main loop\n");

        tcpListener.Start();

        while (!quit) {
            Thread.Sleep(0);
            tcpClient       = tcpListener.AcceptTcpClient();
            agentConnection = new AgentConnection(simulationState, tcpClient);

            //simulationState.stdout.Send(String.Format("CH: accepted client.\n"));

            if (agentConnection.init()) {
                agentConnections.Add(agentConnection);

                request = new InstantiateRequest(agentConnection);
                simulationState.instantiateRequests.Send(request);
                // Block until we get the signal that the agent has been instantiated in the simulation.
                // Then, we can start running it's thread and it's perceive-act loop.
                if (instantiationResults.Recv(out result)) {
                    if (result) {
                        agentConnection.start();
                    }
                    else {
                        Debug.Log("CH Error: instantiation unsuccesful.");
                    }
                }
                else {
                    Debug.LogError("CH Error: instantiation empty.");
                }
            }
        }
        //simulationState.stdout.Send("CH: exit main loop.\n");
    }
Beispiel #24
0
 public NodeActionDispatcher(AgentConnection client, double interval) : base(client, interval)
 {
     actionQueue = new ConcurrentQueue <ActionRequest>();
 }
 public NodeStatusProcessor(AgentConnection agent) : base(agent)
 {
 }
 public ClientRegistrationDispatcher(AgentConnection client, double interval) : base(client, interval)
 {
 }
Beispiel #27
0
 public AgentRegistrationProcessor(AgentConnection agent) : base(agent)
 {
 }
Beispiel #28
0
 public ResourceFromClientDispatcher(AgentConnection client, double interval) : base(client, interval)
 {
     deploymentQueue = new ConcurrentQueue <Resource>();
 }
Beispiel #29
0
 public InstantiateRequest(AgentConnection AC)
 {
     this.agentConnection = AC;
 }
Beispiel #30
0
        public async Task TestAgentDemo()
        {
            var endpoint           = "127.0.0.1:9801";
            var listenerWalletName = "listenerWallet";
            var trusteeWalletName  = "trusteeWallet";
            var message            = "test";

            //1. Create and Open Pool
            var poolName = PoolUtils.CreatePoolLedgerConfig();
            var pool     = await Pool.OpenPoolLedgerAsync(poolName, "{}");

            //2. Create and Open Listener Wallet
            await Wallet.CreateWalletAsync(poolName, listenerWalletName, "default", null, null);

            var listenerWallet = await Wallet.OpenWalletAsync(listenerWalletName, null, null);

            //3. Create and Open Trustee Wallet
            await Wallet.CreateWalletAsync(poolName, trusteeWalletName, "default", null, null);

            var trusteeWallet = await Wallet.OpenWalletAsync(trusteeWalletName, null, null);

            var senderWallet = trusteeWallet;

            //4. Create My Did
            var createMyDidResult = await Signus.CreateAndStoreMyDidAsync(listenerWallet, "{}");

            var listenerDid    = createMyDidResult.Did;
            var listenerVerkey = createMyDidResult.VerKey;
            var listenerPk     = createMyDidResult.Pk;

            //5. Create Their Did from Trustee seed
            var trusteeDidJson = "{\"seed\":\"000000000000000000000000Trustee1\"}";

            var trusteeDidResult = await Signus.CreateAndStoreMyDidAsync(trusteeWallet, trusteeDidJson);

            var trusteeDid = trusteeDidResult.Did;
            var senderDid  = trusteeDid;

            // 6. Prepare and Send NYM request with signing
            var nymRequest = await Ledger.BuildNymRequestAsync(trusteeDid, listenerDid, listenerVerkey, null, null);

            await Ledger.SignAndSubmitRequestAsync(pool, trusteeWallet, trusteeDid, nymRequest);

            // 7. Prepare and Send Attrib for listener (will be requested from ledger and used by sender at start connection)
            var rawJson       = string.Format("{{\"endpoint\":{{\"ha\":\"{0}\",\"verkey\":\"{1}\"}}}}", endpoint, listenerPk);
            var attribRequest = await Ledger.BuildAttribRequestAsync(listenerDid, listenerDid, null, rawJson, null);

            await Ledger.SignAndSubmitRequestAsync(pool, listenerWallet, listenerDid, attribRequest);

            // 8. start listener on endpoint
            var activeListener = await AgentListener.ListenAsync(endpoint);

            // 9. Allow listener accept incoming connection for specific DID (listener_did)
            await activeListener.AddIdentityAsync(pool, listenerWallet, listenerDid);

            // 10. Initiate connection from sender to listener
            var connection = await AgentConnection.ConnectAsync(pool, senderWallet, senderDid, listenerDid);

            // 11. Send test message from sender to listener
            await connection.SendAsync("test");

            var serverConnectionEvent = await activeListener.WaitForConnection();

            var serverConnection = serverConnectionEvent.Connection;
            var messageEvent     = await serverConnection.WaitForMessage();

            Assert.AreEqual(message, messageEvent.Message);

            // 12. Close connection
            await connection.CloseAsync();

            // 13. Close listener
            await activeListener.CloseAsync();

            // 14. Close and delete Issuer Wallet
            await listenerWallet.CloseAsync();

            await Wallet.DeleteWalletAsync(listenerWalletName, null);

            // 15. Close and delete Prover Wallet
            await trusteeWallet.CloseAsync();

            await Wallet.DeleteWalletAsync(trusteeWalletName, null);

            //16. Close Pool
            await pool.CloseAsync();
        }
Beispiel #31
0
 /// <summary>
 /// Initializes a new AgentMessageEvent.
 /// </summary>
 /// <param name="connection">The connection the message was received on.</param>
 /// <param name="result">The result of receiving the message.</param>
 /// <param name="message">The message.</param>
 internal AgentMessageEvent(AgentConnection connection, ErrorCode result, string message) :
     base(connection.Handle, result)
 {
     Connection = connection;
     Message    = message;
 }