use async_ringbuf::{AsyncHeapCons, AsyncHeapProd, AsyncHeapRb, traits::*};
use crossbeam::atomic::AtomicCell;
use std::{
collections::HashMap,
fmt::Debug,
sync::Arc,
task::{Poll, ready},
};
use async_trait::async_trait;
use futures::{Sink, SinkExt, Stream, StreamExt};
use once_cell::sync::Lazy;
use tokio::sync::mpsc::{UnboundedReceiver, UnboundedSender, unbounded_channel};
use uuid::Uuid;
use crate::tunnel::{FromUrl, IpVersion, SinkError, SinkItem};
use super::{
StreamItem, Tunnel, TunnelConnector, TunnelError, TunnelInfo, TunnelListener,
build_url_from_socket_addr, common::TunnelWrapper,
};
pub static RING_TUNNEL_CAP: usize = 128;
static RING_TUNNEL_RESERVED_CAP: usize = 4;
type RingLock = parking_lot::Mutex<()>;
type RingItem = SinkItem;
pub struct RingTunnel {
id: Uuid,
ring_cons_impl: AtomicCell