repo_description: GO Simple Tunnel - a simple tunnel written in golang
repo_topics: dns go golang http2 kcp obfs4 quic shadowsocks sni socks5 ssh tls tunnel tuntap udp
code: package gost
  
  import (
  	"net"
  
  	smux "github.com/xtaci/smux"
  )
  
  type muxStreamConn struct {
  	net.Conn
  	stream *smux.Stream
  }
  
  func (c *muxStreamConn) Read(b []byte) (n int, err error) {
  	return c.stream.Read(b)
  }
  
  func (c *muxStreamConn) Write(b []byte) (n int, err error) {
  	return c.stream.Write(b)
  }
  
  func (c *muxStreamConn) Close() error {
  	return c.stream.Close()
  }
  
  type muxSession struct {
  	conn    net.Conn
  	session *smux.Session
  }
  
  func (session *muxSession) GetConn() (net.Conn, error) {
  	stream, err := session.session.OpenStream()
  	if err != nil {
  		return nil, err
  	}
  	return &muxStreamConn{Conn: session.conn, stream: stream}, nil
  }
  
  func (session *muxSession) Accept() (net.Conn, error) {
  	stream, err := session.session.AcceptStream()
  	if err != nil {
  		return nil, err
  	}
  	return &muxStreamConn{Conn: session.conn, stream: stream}, nil
  }
  
  func (session *muxSession) Close() error {
  	if session.session == nil {
  		return nil
  	}
  	return session.session.Close()
  }
  
  func (session *muxSession) IsClosed() bool {
  	if session.session == nil {
  		return true
  	}
  	return session.session.IsClosed()
  }
  
  func (session *muxSession) NumStreams() int {
  	return session.session.NumStreams()
  }
  