using System.Net;
namespace linker.tunnel.connection
{
    /// 
    /// 隧道协议
    /// 
    public enum TunnelProtocolType : byte
    {
        Tcp = 1,
        Udp = 2,
        Quic = 4,
    }
    /// 
    /// 隧道模式
    /// 
    public enum TunnelMode : byte
    {
        Client = 0,
        Server = 1,
    }
    /// 
    /// 隧道类型
    /// 
    public enum TunnelType : byte
    {
        P2P = 0,
        Relay = 1,
    }
    /// 
    /// 隧道方向
    /// 
    public enum TunnelDirection : byte
    {
        /// 
        /// 正向连接
        /// 
        Forward = 0,
        /// 
        /// 反向连接
        /// 
        Reverse = 1
    }
    public interface ITunnelConnectionReceiveCallback
    {
        public Task Receive(ITunnelConnection connection, ReadOnlyMemory data, object state);
        public Task Closed(ITunnelConnection connection, object state);
    }
    /// 
    /// 隧道连接对象
    /// 
    public interface ITunnelConnection
    {
        /// 
        /// 对方id
        /// 
        public string RemoteMachineId { get; }
        /// 
        /// 对方名称
        /// 
        public string RemoteMachineName { get; }
        /// 
        /// 事务
        /// 
        public string TransactionId { get; }
        /// 
        /// 协议
        /// 
        public string TransportName { get; }
        /// 
        /// 描述
        /// 
        public string Label { get; }
        /// 
        /// 隧道模式
        /// 
        public TunnelMode Mode { get; }
        /// 
        /// 隧道类型
        /// 
        public TunnelType Type { get; }
        /// 
        /// 协议
        /// 
        public TunnelProtocolType ProtocolType { get; }
        /// 
        /// 隧道方向
        /// 
        public TunnelDirection Direction { get; }
        /// 
        /// 对方IP
        /// 
        public IPEndPoint IPEndPoint { get; }
        /// 
        /// 是否SSL
        /// 
        public bool SSL { get; }
        /// 
        /// 已连接
        /// 
        public bool Connected { get; }
        /// 
        /// 延迟
        /// 
        public int Delay { get; }
        /// 
        /// 已发送字节数
        /// 
        public long SendBytes { get; }
        /// 
        /// 已接受字节数
        /// 
        public long ReceiveBytes { get; }
        /// 
        /// 发送ping
        /// 
        /// 
        public Task SendPing();
        /// 
        /// 发送数据
        /// 
        /// 
        /// 
        public ValueTask SendAsync(ReadOnlyMemory data);
        /// 
        /// 开始接收数据
        /// 
        /// 收到数据的回调
        /// 自定义数据,回调带上
        /// 是否分包
        public void BeginReceive(ITunnelConnectionReceiveCallback callback, object userToken, bool framing = true);
        /// 
        /// 关闭隧道
        /// 
        public void Dispose();
        public string ToString();
    }
}