Ejemplo n.º 1
0
 /// <summary>
 /// Forwards the current contents of this connection's buffer to the
 /// specified service.
 /// </summary>
 /// <param name="service">The service to forward to.</param>
 /// <param name="callback">
 /// A callback to notify when current buffer forwarding has completed.
 /// </param>
 public void ForwardBufferTo(
     ServiceConnection service,
     InitiateForwardingCallback callback)
 {
     this.service = service;
     this.forwardingCallback = callback;
     this.SendMessage();
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Handles successfully accepted service connections.
 /// </summary>
 /// <param name="accepted">
 /// The socket for the newly accepted connection.
 /// </param>
 private void ServiceConnectionAccepted(Socket accepted)
 {
     ServiceConnection connection = new ServiceConnection(
         accepted,
         this.keymaster,
         this.matchmaker);
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Matches a service connection to a waiting client and
        /// initiates forwarding operations.
        /// </summary>
        /// <param name="connection">
        /// Service connection for forwarding to client.
        /// </param>
        /// <param name="token">
        /// An unique identifier for this client instance.
        /// </param>
        /// <returns>
        /// True if forwarding was established, false otherwise.
        /// </returns>
        public bool MatchToClient(ServiceConnection connection, uint token)
        {
            ClientConnection found;
            lock (this.waitingClients)
            {
                this.waitingClients.TryGetValue(token, out found);
                if ((found == null) || !this.waitingClients.Remove(token))
                {
                    return false;
                }
            }

            // -
            // We first need to forward found's outstanding receive buffer to
            // this connection.  After that completes, it will call us back to
            // initiate perpetual forwarding.
            // -
            found.ForwardBufferTo(connection, this.InitiateForwarding);

            return true;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Registers a service with the matchmaker.
        /// </summary>
        /// <param name="id">An identifier for the service.</param>
        /// <param name="connection">
        /// The control connection to this service.
        /// </param>
        /// <returns>True if successfully registered, false otherwise.</returns>
        public bool RegisterService(string id, ServiceConnection connection)
        {
            try
            {
                lock (this.registeredServices)
                {
                    this.registeredServices.Add(id, connection);
                }
            }
            catch (ArgumentException)
            {
                return false;
            }

            return true;
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Starts a new forwarding agent to bi-directionally transfer data
 /// between an existing client connection and an existing service
 /// connection.
 /// </summary>
 /// <param name="client">The client connection.</param>
 /// <param name="service">The service connection.</param>
 public void InitiateForwarding(
     ClientConnection client,
     ServiceConnection service)
 {
     // -
     // Initiate bi-directional forwarding.
     // -
     Forwarder forwarder = new Forwarder(
         client.Socket,
         service.Socket,
         this.MatchEnding);
     lock (this.matches)
     {
         this.matches.Add(forwarder);
     }
 }