Example #1
0
        /// <summary>
        /// Obtains relay using its ID, caller's token, or callee's token.
        /// </summary>
        /// <param name="Guid">Relay ID, caller's token, or callee's token</param>
        /// <returns>Relay that corresponds to the given GUID, or null if no such relay exists.</returns>
        public RelayConnection GetRelayByGuid(Guid Guid)
        {
            log.Trace("(Guid:'{0}')", Guid);

            RelayConnection res = null;

            lock (lockObject)
            {
                relaysByGuid.TryGetValue(Guid, out res);
            }

            if (res != null)
            {
                log.Trace("(-):*.Id='{0}'", res.GetId());
            }
            else
            {
                log.Trace("(-):null");
            }
            return(res);
        }
Example #2
0
        /// <summary>
        /// Destroys relay connection and all references to it.
        /// </summary>
        /// <param name="Relay">Relay connection to destroy.</param>
        public async Task DestroyNetworkRelay(RelayConnection Relay)
        {
            log.Trace("(Relay.id:'{0}')", Relay.GetId());

            bool destroyed = await Relay.TestAndSetDestroyed();

            if (!destroyed)
            {
                bool relayIdRemoved     = false;
                bool callerTokenRemoved = false;
                bool calleeTokenRemoved = false;
                lock (lockObject)
                {
                    relayIdRemoved     = relaysByGuid.Remove(Relay.GetId());
                    callerTokenRemoved = relaysByGuid.Remove(Relay.GetCallerToken());
                    calleeTokenRemoved = relaysByGuid.Remove(Relay.GetCalleeToken());
                }

                if (!relayIdRemoved)
                {
                    log.Error("Relay ID '{0}' not found in relay list.", Relay.GetId());
                }
                if (!callerTokenRemoved)
                {
                    log.Error("Caller token '{0}' not found in relay list.", Relay.GetCallerToken());
                }
                if (!calleeTokenRemoved)
                {
                    log.Error("Callee token '{0}' not found in relay list.", Relay.GetCalleeToken());
                }

                Relay.Dispose();
            }
            else
            {
                log.Trace("Relay ID '{0}' has been destroyed already.", Relay.GetId());
            }

            log.Trace("(-)");
        }
Example #3
0
        /// <summary>
        /// Creates a new network relay between a caller identity and one of the node's customer identities that is online.
        /// </summary>
        /// <param name="Caller">Initiator of the call.</param>
        /// <param name="Callee">Node's customer client to be called.</param>
        /// <param name="ServiceName">Name of the application service to use.</param>
        /// <param name="RequestMessage">CallIdentityApplicationServiceRequest message that the caller send in order to initiate the call.</param>
        /// <returns>New relay connection object if the function succeeds, or null otherwise.</returns>
        public RelayConnection CreateNetworkRelay(Client Caller, Client Callee, string ServiceName, Message RequestMessage)
        {
            log.Trace("(Caller.Id:{0:X16},Callee.Id:{1:X16},ServiceName:'{2}')", Caller.Id, Callee.Id, ServiceName);

            RelayConnection res = null;

            RelayConnection relay = new RelayConnection(Caller, Callee, ServiceName, RequestMessage);

            lock (lockObject)
            {
                relaysByGuid.Add(relay.GetId(), relay);
                relaysByGuid.Add(relay.GetCallerToken(), relay);
                relaysByGuid.Add(relay.GetCalleeToken(), relay);
            }

            log.Debug("Relay ID '{0}' added to the relay list.", relay.GetId());
            log.Debug("Caller token '{0}' added to the relay list.", relay.GetCallerToken());
            log.Debug("Callee token '{0}' added to the relay list.", relay.GetCalleeToken());

            res = relay;

            log.Trace("(-):{0}", res);
            return(res);
        }
 /// <summary>
 /// Initializes the relay message context.
 /// </summary>
 public RelayMessageContext(RelayConnection Relay, Message SenderRequest)
 {
     this.Relay         = Relay;
     this.SenderRequest = SenderRequest;
 }