/// <summary>
            /// Initializes a new instance of the PerDirection class.
            /// </summary>
            /// <param name="forwarder">
            /// The forwarder object to which this instance belongs.
            /// </param>
            /// <param name="from">The connection to read from.</param>
            /// <param name="to">The connection to write to.</param>
            public PerDirection(Forwarder forwarder, Stream from, Stream to, DiagnosticsHelper wd)
            {
                this.wd = wd;
#region ENTER
using (AutoEnterExitTrace aeet = new AutoEnterExitTrace(wd, wd.WebTrace, "Forwarder_PerDirection_ctor()"))
{
#endregion ENTER

                aeet.WriteDiagnosticInfo(System.Diagnostics.TraceEventType.Information, TraceEventID.traceFlow, "PerDirection Forwarder object: {0} was created for streams:  from:{1} to:{2}", this.GetHashCode(), from.GetHashCode(), to.GetHashCode());
                
                this.forwarder = forwarder;
                this.inbound = from;
                this.outbound = to;
                this.buffer = new byte[1500];
                this.streamBufState = new StreamBufferState();
                this.streamBufState.SetBuffer(this.buffer, 0, this.buffer.Length);

                // -
                // Start things going by issuing a receive on the inbound side.
                // -
                this.StartReceive();
#region LEAVE
}
#endregion LEAVE
            }
        /// <summary>
        /// Handler for forwarded connections.
        /// </summary>
        /// <param name="connection">
        /// The connection being forwarded.
        /// </param>
        /// <returns>
        /// True if forwarding was established, false otherwise.
        /// </returns>
        private bool Forwarding(ServiceConnection connection)
        {
            Socket localService = StaticUtilities.CreateConnectedSocket(
                "localhost",
                HomeOS.Hub.Common.Constants.InfoServicePort);

            NetworkStream netstream = new NetworkStream(localService, true /*ownSocket*/);

            if (localService != null)
            {
                Forwarder forwarder = new Forwarder(
                    netstream,
                    connection.GetStream(),
                    this.StopForwarding, null);
                return true;
            }

            return false;
        }
Example #3
0
 /// <summary>
 /// Removes a forwarding pair from our list of matches.
 /// </summary>
 /// <param name="forwarder">The forwarder to remove.</param>
 private void MatchEnding(Forwarder forwarder)
 {
     lock (this.matches)
     {
         this.matches.Remove(forwarder);
     }
 }
Example #4
0
 /// <summary>
 /// Handler for end-of-forwarding event.
 /// </summary>
 /// <param name="forwarder">The forwarder that is closing.</param>
 private void StopForwarding(HomeOS.Shared.Gatekeeper.Forwarder forwarder)
 {
 }
Example #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);
     }
 }