Esempio n. 1
0
        /// <summary>
        /// Creates a new outgoing connection.
        /// </summary>
        /// <remarks>
        /// <para>When establishing a connection two DIDs are required, one for the sender identity (who is
        /// initiating the connection) and the other for the receiver identity (who the connection is being
        /// established with).
        /// </para>
        /// <para>The <see cref="Wallet"/> provided when creating the connection must contain information about
        /// the sender identity which must have been added using the <see cref="Signus.CreateAndStoreMyDidAsync(Wallet, string)"/>
        /// method prior to attempting to create the connection.
        /// </para>
        /// <para>The identity information for the receiver can also be stored in the wallet using
        /// the <see cref="Signus.StoreTheirDidAsync(Wallet, string)"/> method, however if no record is
        /// present in the wallet the identity information will be established from the ledger in the
        /// provided node <see cref="Pool"/> and will automatically be cached in the provided wallet.
        /// </para>
        /// </remarks>
        /// <seealso cref="Pool"/>
        /// <seealso cref="Wallet"/>
        /// <seealso cref="Signus"/>
        /// <param name="pool">The node pool that the destination DID is registered on.</param>
        /// <param name="wallet">The wallet containing the sender (and optionally receiver) DID.</param>
        /// <param name="senderDid">The DID of the identity imitating the connection.</param>
        /// <param name="receiverDid">The DID of the identity the connection is to be established with.</param>
        /// <returns>An asynchronous <see cref="Task{T}"/> that resolves to an AgentConnection instance
        /// when the connection has been established.</returns>
        public static Task <AgentConnection> ConnectAsync(Pool pool, Wallet wallet, string senderDid, string receiverDid)
        {
            ParamGuard.NotNull(pool, "pool");
            ParamGuard.NotNull(wallet, "wallet");
            ParamGuard.NotNullOrWhiteSpace(senderDid, "senderDid");
            ParamGuard.NotNullOrWhiteSpace(receiverDid, "receiverDid");

            var connection = new AgentConnection();

            var taskCompletionSource = new TaskCompletionSource <AgentConnection>(connection);
            var commandHandle        = PendingCommands.Add(taskCompletionSource);

            var result = IndyNativeMethods.indy_agent_connect(
                commandHandle,
                pool.Handle,
                wallet.Handle,
                senderDid,
                receiverDid,
                _connectionEstablishedCallback,
                connection.MessageReceivedCallback);

            CallbackHelper.CheckResult(result);

            return(taskCompletionSource.Task);
        }
 /// <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)
 {
     Listener    = listener ?? throw new ArgumentNullException("listener");
     Connection  = connection ?? throw new ArgumentNullException("connection");;
     SenderDid   = senderDid;
     ReceiverDid = receiverDid;
 }
Esempio n. 3
0
        /// <summary>
        /// Callback to use when am incoming connection is established to a listener.
        /// </summary>
        private void ConnectionEstablishedHandler(IntPtr listener_handle, int err, IntPtr connection_handle, string sender_did, string receiver_did)
        {
            Debug.Assert(!_connections.ContainsKey(connection_handle));

            var connection = new AgentConnection(connection_handle);

            _connections.Add(connection_handle, connection);

            _events.Add(new AgentConnectionEvent(this, (ErrorCode)err, connection, sender_did, receiver_did));
            NotifyEventWaiters();
        }
Esempio n. 4
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 ?? throw new ArgumentNullException("connection");
     Message    = message ?? throw new ArgumentNullException("message");
 }