Abstract base class for HeliosTransport - has separate child implementations for TCP / UDP respectively
Inheritance: Transport
Esempio n. 1
0
        /// <summary>
        /// Converts a <see cref="ByteString"/> structure into a Helios <see cref="NetworkData"/> structure
        /// </summary>
        /// <param name="byteString">The data to send over the network</param>
        /// <param name="address">The address that we received data from / are sending data to</param>
        /// <returns>a new <see cref="NetworkData"/> struct</returns>
        public static NetworkData ToData(ByteString byteString, Address address)
        {
            var data = new NetworkData()
            {
                Buffer     = byteString.ToByteArray(),
                RemoteHost = HeliosTransport.AddressToNode(address)
            };

            data.Length = data.Buffer.Length;
            return(data);
        }
        void InitInbound(IChannel channel, IPEndPoint socketAddress, object msg)
        {
            // disable automatic reads
            channel.Configuration.AutoRead = false;

            _associationEventListener.ContinueWith(r =>
            {
                var listener      = r.Result;
                var remoteAddress = HeliosTransport.MapSocketToAddress(socketAddress, WrappedTransport.SchemeIdentifier,
                                                                       WrappedTransport.System.Name);
                AssociationHandle handle;
                Init(channel, socketAddress, remoteAddress, msg, out handle);
                listener.Notify(new InboundAssociation(handle));
            }, TaskContinuationOptions.OnlyOnRanToCompletion);
        }
Esempio n. 3
0
        protected void InitInbound(IConnection connection, INode remoteSocketAddress, NetworkData msg)
        {
            _associationListenerTask.ContinueWith(r =>
            {
                var listener      = r.Result;
                var remoteAddress = HeliosTransport.NodeToAddress(remoteSocketAddress, WrappedTransport.SchemeIdentifier,
                                                                  WrappedTransport.System.Name);

                if (remoteAddress == null)
                {
                    throw new HeliosNodeException("Unknown inbound remote address type {0}", remoteSocketAddress);
                }
                AssociationHandle handle;
                Init(connection, remoteSocketAddress, remoteAddress, msg, out handle);
                listener.Notify(new InboundAssociation(handle));
            }, TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.NotOnCanceled | TaskContinuationOptions.NotOnFaulted);
        }
Esempio n. 4
0
        protected void Init(IConnection channel, INode remoteSocketAddress, Address remoteAddress, NetworkData msg,
                            out AssociationHandle op)
        {
            var localAddress = HeliosTransport.NodeToAddress(channel.Local, WrappedTransport.SchemeIdentifier,
                                                             WrappedTransport.System.Name, WrappedTransport.Settings.Hostname);

            if (localAddress != null)
            {
                var handle = CreateHandle(channel, localAddress, remoteAddress);
                handle.ReadHandlerSource.Task.ContinueWith(s =>
                {
                    var listener = s.Result;
                    RegisterListener(channel, listener, msg, remoteSocketAddress);
                }, TaskContinuationOptions.AttachedToParent & TaskContinuationOptions.ExecuteSynchronously & TaskContinuationOptions.NotOnCanceled & TaskContinuationOptions.NotOnFaulted);
                op = handle;
            }
            else
            {
                op = null;
                channel.Close();
            }
        }
Esempio n. 5
0
        /// <summary>
        /// TBD
        /// </summary>
        /// <param name="channel">TBD</param>
        /// <param name="remoteSocketAddress">TBD</param>
        /// <param name="remoteAddress">TBD</param>
        /// <param name="msg">TBD</param>
        /// <param name="op">TBD</param>
        protected void Init(IChannel channel, IPEndPoint remoteSocketAddress, Address remoteAddress, object msg,
                            out AssociationHandle op)
        {
            var localAddress = HeliosTransport.MapSocketToAddress((IPEndPoint)channel.LocalAddress, WrappedTransport.SchemeIdentifier,
                                                                  WrappedTransport.System.Name, WrappedTransport.Settings.Hostname);

            if (localAddress != null)
            {
                var handle = CreateHandle(channel, localAddress, remoteAddress);
                handle.ReadHandlerSource.Task.ContinueWith(s =>
                {
                    var listener = s.Result;
                    RegisterListener(channel, listener, msg, remoteSocketAddress);
                    channel.Configuration.AutoRead = true; // turn reads back on
                }, TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.NotOnCanceled | TaskContinuationOptions.NotOnFaulted);
                op = handle;
            }
            else
            {
                op = null;
                channel.CloseAsync();
            }
        }
Esempio n. 6
0
 protected ClientHandler(HeliosTransport heliosWrappedTransport, Address remoteAddress, IConnection underlyingConnection) : base(underlyingConnection)
 {
     WrappedTransport = heliosWrappedTransport;
     RemoteAddress    = remoteAddress;
 }
Esempio n. 7
0
 protected ServerHandler(HeliosTransport wrappedTransport, Task <IAssociationEventListener> associationListenerTask, IConnection underlyingConnection) : base(underlyingConnection)
 {
     WrappedTransport         = wrappedTransport;
     _associationListenerTask = associationListenerTask;
 }
Esempio n. 8
0
 public TcpAssociationHandle(Address localAddress, Address remoteAddress, HeliosTransport transport, IConnection connection)
     : base(localAddress, remoteAddress)
 {
     _channel = connection;
     _transport = transport;
 }
Esempio n. 9
0
 public TcpClientHandler(HeliosTransport heliosWrappedTransport, Address remoteAddress, IConnection underlyingConnection)
     : base(underlyingConnection)
 {
     WrappedTransport = heliosWrappedTransport;
     RemoteAddress = remoteAddress;
 }
Esempio n. 10
0
 public TcpServerHandler(HeliosTransport wrappedTransport, Task<IAssociationEventListener> associationListenerTask, IConnection underlyingConnection)
     : base(underlyingConnection)
 {
     WrappedTransport = wrappedTransport;
     _associationListenerTask = associationListenerTask;
 }
Esempio n. 11
0
 public TcpAssociationHandle(Address localAddress, Address remoteAddress, HeliosTransport transport, IConnection connection)
     : base(localAddress, remoteAddress)
 {
     _channel   = connection;
     _transport = transport;
 }
Esempio n. 12
0
 /// <summary>
 /// TBD
 /// </summary>
 /// <param name="wrappedTransport">TBD</param>
 /// <param name="log">TBD</param>
 /// <param name="remoteAddress">TBD</param>
 public TcpClientHandler(HeliosTransport wrappedTransport, ILoggingAdapter log, Address remoteAddress) : base(wrappedTransport, log)
 {
     _remoteAddress = remoteAddress;
 }
Esempio n. 13
0
 /// <summary>
 /// TBD
 /// </summary>
 /// <param name="wrappedTransport">TBD</param>
 /// <param name="log">TBD</param>
 /// <param name="associationEventListener">TBD</param>
 public TcpServerHandler(HeliosTransport wrappedTransport, ILoggingAdapter log, Task <IAssociationEventListener> associationEventListener) : base(wrappedTransport, log)
 {
     _associationEventListener = associationEventListener;
 }
Esempio n. 14
0
 public TcpServerHandler(HeliosTransport wrappedTransport, ILoggingAdapter log, Task<IAssociationEventListener> associationEventListener) : base(wrappedTransport, log)
 {
     _associationEventListener = associationEventListener;
 }
Esempio n. 15
0
 protected TcpHandlers(HeliosTransport wrappedTransport, ILoggingAdapter log) : base(wrappedTransport, log)
 {
 }
Esempio n. 16
0
 public TcpClientHandler(HeliosTransport wrappedTransport, ILoggingAdapter log, Address remoteAddress) : base(wrappedTransport, log)
 {
     _remoteAddress = remoteAddress;
 }
Esempio n. 17
0
 /// <summary>
 /// TBD
 /// </summary>
 /// <param name="wrappedTransport">TBD</param>
 /// <param name="log">TBD</param>
 protected TcpHandlers(HeliosTransport wrappedTransport, ILoggingAdapter log) : base(wrappedTransport, log)
 {
 }
Esempio n. 18
0
 /// <summary>
 /// TBD
 /// </summary>
 /// <param name="wrappedTransport">TBD</param>
 /// <param name="log">TBD</param>
 protected CommonHandlers(HeliosTransport wrappedTransport, ILoggingAdapter log)
 {
     WrappedTransport = wrappedTransport;
     Log = log;
 }
Esempio n. 19
0
 protected CommonHandlers(HeliosTransport wrappedTransport, ILoggingAdapter log)
 {
     WrappedTransport = wrappedTransport;
     Log = log;
 }