mirror of
https://github.com/hbahadorzadeh/stunning.git
synced 2025-12-24 13:38:08 +08:00
Closed added to tunnels to be able to monitor them
This commit is contained in:
@@ -8,4 +8,5 @@ type TunnelInterfaceClient interface {
|
||||
HandleConnection(conn net.Conn, tconn net.Conn) error
|
||||
WaitingForConnection()
|
||||
Close()
|
||||
Closed() bool
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package serial
|
||||
|
||||
import (
|
||||
"github.com/jacobsa/go-serial/serial"
|
||||
icommon "github.com/hbahadorzadeh/stunning/interface/common"
|
||||
tcommon "github.com/hbahadorzadeh/stunning/tunnel/common"
|
||||
"github.com/jacobsa/go-serial/serial"
|
||||
"io"
|
||||
"log"
|
||||
"net"
|
||||
|
||||
@@ -13,6 +13,7 @@ type SocksClient struct {
|
||||
tun_dialer tcommon.TunnelDialer
|
||||
saddress string
|
||||
listen net.Listener
|
||||
closed bool
|
||||
}
|
||||
|
||||
func GetSocksClient(url, surl string, tun_dialer tcommon.TunnelDialer) *SocksClient {
|
||||
@@ -25,6 +26,7 @@ func GetSocksClient(url, surl string, tun_dialer tcommon.TunnelDialer) *SocksCli
|
||||
log.Panic(err)
|
||||
}
|
||||
s.listen = listen
|
||||
s.closed = false
|
||||
return s
|
||||
}
|
||||
|
||||
@@ -53,6 +55,11 @@ func (t SocksClient) HandleConnection(conn net.Conn, tconn net.Conn) error {
|
||||
|
||||
func (t SocksClient) Close() {
|
||||
t.listen.Close()
|
||||
t.closed = true
|
||||
}
|
||||
|
||||
func (t SocksClient) Closed() bool {
|
||||
return t.closed
|
||||
}
|
||||
|
||||
func tcp_reader(conn net.Conn, tconn net.Conn) {
|
||||
|
||||
@@ -13,10 +13,11 @@ type TcpClient struct {
|
||||
tun_dialer tcommon.TunnelDialer
|
||||
saddress string
|
||||
listen net.Listener
|
||||
closed bool
|
||||
}
|
||||
|
||||
func GetTcpClient(url, surl string, tun_dialer tcommon.TunnelDialer) *TcpClient {
|
||||
s := &TcpClient{}
|
||||
func GetTcpClient(url, surl string, tun_dialer tcommon.TunnelDialer) TcpClient {
|
||||
s := TcpClient{}
|
||||
s.address = url
|
||||
s.saddress = surl
|
||||
s.tun_dialer = tun_dialer
|
||||
@@ -25,11 +26,12 @@ func GetTcpClient(url, surl string, tun_dialer tcommon.TunnelDialer) *TcpClient
|
||||
log.Panic(err)
|
||||
}
|
||||
s.listen = listen
|
||||
s.closed = false
|
||||
return s
|
||||
}
|
||||
|
||||
func (t *TcpClient) WaitingForConnection() {
|
||||
for {
|
||||
for !t.closed {
|
||||
conn, err := t.listen.Accept()
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
@@ -42,11 +44,20 @@ func (t *TcpClient) WaitingForConnection() {
|
||||
}
|
||||
go t.HandleConnection(conn, sconn)
|
||||
}
|
||||
t.closed = true
|
||||
}
|
||||
|
||||
func (t *TcpClient) HandleConnection(conn net.Conn, tconn net.Conn) error {
|
||||
func (t TcpClient) HandleConnection(conn net.Conn, tconn net.Conn) error {
|
||||
log.Printf("Socket to %s handling connection \n", t.address)
|
||||
go tcp_reader(conn, tconn)
|
||||
tcp_writer(conn, tconn)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *TcpClient) Close() {
|
||||
t.closed = true
|
||||
}
|
||||
|
||||
func (t TcpClient) Closed() bool {
|
||||
return t.closed
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package tun
|
||||
|
||||
import (
|
||||
"github.com/songgao/water"
|
||||
"github.com/hbahadorzadeh/stunning/common"
|
||||
icommon "github.com/hbahadorzadeh/stunning/interface/common"
|
||||
tcommon "github.com/hbahadorzadeh/stunning/tunnel/common"
|
||||
"github.com/songgao/water"
|
||||
"log"
|
||||
"net"
|
||||
"os"
|
||||
@@ -15,8 +15,8 @@ import (
|
||||
type TunInterface struct {
|
||||
icommon.TunnelInterfaceServer
|
||||
icommon.TunnelInterfaceClient
|
||||
conf TunConfig
|
||||
iface *water.Interface
|
||||
conf TunConfig
|
||||
iface *water.Interface
|
||||
stopped bool
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ type TunInterfaceClient struct {
|
||||
TunInterface
|
||||
address string
|
||||
dialer tcommon.TunnelDialer
|
||||
closed bool
|
||||
}
|
||||
|
||||
type TunConfig struct {
|
||||
@@ -47,8 +48,8 @@ func GetTunIface(config TunConfig) TunInterface {
|
||||
}
|
||||
|
||||
iface := TunInterface{
|
||||
iface: ifce,
|
||||
conf: config,
|
||||
iface: ifce,
|
||||
conf: config,
|
||||
stopped: false,
|
||||
}
|
||||
return iface
|
||||
@@ -73,6 +74,7 @@ func GetTunIfaceClient(config TunConfig, addr string, d tcommon.TunnelDialer) Tu
|
||||
}
|
||||
iface.iface = ifce
|
||||
iface.conf = config
|
||||
iface.closed = false
|
||||
return iface
|
||||
}
|
||||
|
||||
@@ -137,21 +139,30 @@ func runIP(args ...string) {
|
||||
}
|
||||
}
|
||||
|
||||
func (t TunInterfaceClient) WaitingForConnection() {
|
||||
func (t *TunInterfaceClient) WaitingForConnection() {
|
||||
conn, err := t.dialer.Dial(t.dialer.Protocol().String(), t.address)
|
||||
if err == nil {
|
||||
t.HandleConnection(conn)
|
||||
}
|
||||
t.closed = true
|
||||
}
|
||||
|
||||
func (t *TunInterfaceClient) Close() {
|
||||
t.iface.Close()
|
||||
t.closed = true
|
||||
}
|
||||
|
||||
func (t TunInterfaceClient) Closed() bool {
|
||||
return t.closed
|
||||
}
|
||||
|
||||
func (t TunInterface) WaitingForConnection() {
|
||||
for !t.stopped{
|
||||
for !t.stopped {
|
||||
time.Sleep(time.Second)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func (t TunInterface) Close() error {
|
||||
t.stopped = true
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ type udp_client struct {
|
||||
conn *net.UDPConn
|
||||
replyMap []*common.UdpAddress
|
||||
mux sync.Mutex
|
||||
closed bool
|
||||
}
|
||||
|
||||
func GetUdpClient(url string) *udp_client {
|
||||
@@ -45,8 +46,18 @@ func GetUdpClient(url string) *udp_client {
|
||||
}
|
||||
s.mux.Unlock()
|
||||
}()
|
||||
s.closed = false
|
||||
return s
|
||||
}
|
||||
|
||||
func (c *udp_client) Close() {
|
||||
c.closed = true
|
||||
}
|
||||
|
||||
func (c udp_client) Closed() bool {
|
||||
return c.closed
|
||||
}
|
||||
|
||||
func (c *udp_client) WaitingForConnection() {
|
||||
|
||||
}
|
||||
|
||||
@@ -10,11 +10,13 @@ type TunnelServer interface {
|
||||
SetServer(server icommon.TunnelInterfaceServer)
|
||||
WaitingForConnection()
|
||||
Close() error
|
||||
Closed() bool
|
||||
HandleConnection(conn net.Conn)
|
||||
}
|
||||
|
||||
type TunnelServerCommon struct {
|
||||
TunnelServer
|
||||
closed bool
|
||||
Server icommon.TunnelInterfaceServer
|
||||
Listener net.Listener
|
||||
}
|
||||
@@ -24,6 +26,7 @@ func (s TunnelServerCommon) SetServer(ss icommon.TunnelInterfaceServer) {
|
||||
}
|
||||
|
||||
func (s TunnelServerCommon) WaitingForConnection() {
|
||||
s.closed = false
|
||||
log.Printf("listening for connection on %s\n", s.Listener.Addr().String())
|
||||
for {
|
||||
conn, err := s.Listener.Accept()
|
||||
@@ -34,12 +37,19 @@ func (s TunnelServerCommon) WaitingForConnection() {
|
||||
}
|
||||
go s.HandleConnection(conn)
|
||||
}
|
||||
s.closed = true
|
||||
log.Printf("Listening on %s stopped\n", s.Listener.Addr().String())
|
||||
}
|
||||
|
||||
func (s TunnelServerCommon) Close() error {
|
||||
log.Println("Closing connection")
|
||||
return s.Listener.Close()
|
||||
err := s.Listener.Close()
|
||||
s.closed = true
|
||||
return err
|
||||
}
|
||||
|
||||
func (s TunnelServerCommon) Closed() bool {
|
||||
return s.closed
|
||||
}
|
||||
|
||||
func (s TunnelServerCommon) HandleConnection(conn net.Conn) {
|
||||
|
||||
Reference in New Issue
Block a user