func makeSession() *Session { session := &Session{ Closer: closer.NewCloser(), Signaler: signaler.NewSignaler(), conns: make(map[uint32]*Conn), closedConnIds: list.New(), newTransport: make(chan Transport, 128), errTransport: make(chan Transport), incomingPackets: make(chan *Packet), incomingPacketsMap: make(map[string]*Packet), incomingAcks: make(chan *Packet), recvIn: make(chan *Packet), Recv: make(chan *Packet), outgoingPackets: make(chan *Packet), sendingPacketsMap: make(map[string]*Packet), outCheckTicker: time.NewTicker(time.Millisecond * 100), getTransportCount: make(chan int), getStatResend: make(chan int), } recvLink := ic.Link(session.recvIn, session.Recv) session.OnClose(func() { close(recvLink) session.CloseSignaler() }) session.setDebugEntries() go session.start() return session }
func New(listenAddr string) (*SocksServer, error) { server := &SocksServer{ Signaler: signaler.NewSignaler(), Closer: closer.NewCloser(), } ln, err := net.Listen("tcp", listenAddr) if err != nil { return nil, err } server.OnClose(func() { ln.Close() }) go func() { for { conn, err := ln.Accept() if err != nil { if server.IsClosing { return } continue } go server.handshake(conn) } }() return server, nil }