StartWithConfigAndContext starts the SOCKS5 proxy server with configuration and context support
(ctx context.Context, port int, quicConn quic.Connection, bufferSize int)
| 889 | |
| 890 | // StartWithConfigAndContext starts the SOCKS5 proxy server with configuration and context support |
| 891 | func (p *DefaultProxy) StartWithConfigAndContext(ctx context.Context, port int, quicConn quic.Connection, bufferSize int) error { |
| 892 | socksAddr := fmt.Sprintf(":%d", port) |
| 893 | socksListener, err := net.Listen("tcp", socksAddr) |
| 894 | if err != nil { |
| 895 | return fmt.Errorf("failed to start SOCKS5 server: %w", err) |
| 896 | } |
| 897 | defer socksListener.Close() |
| 898 | |
| 899 | // Set up graceful shutdown |
| 900 | go func() { |
| 901 | <-ctx.Done() |
| 902 | shared.LogNetwork("Shutting down SOCKS5 proxy server") |
| 903 | socksListener.Close() |
| 904 | }() |
| 905 | |
| 906 | shared.LogSuccessf("SOCKS5 proxy server started on %s (optimized)", socksAddr) |
| 907 | shared.LogInfof("Configure your browser to use SOCKS5 proxy: localhost%s", socksAddr) |
| 908 | |
| 909 | // Accept SOCKS5 connections |
| 910 | for { |
| 911 | conn, err := socksListener.Accept() |
| 912 | if err != nil { |
| 913 | // Check if this is due to context cancellation (expected) |
| 914 | if ctx.Err() != nil { |
| 915 | shared.LogNetwork("SOCKS5 proxy server shutdown completed") |
| 916 | return nil |
| 917 | } |
| 918 | // Check if listener was closed |
| 919 | if ne, ok := err.(net.Error); ok && !ne.Temporary() { |
| 920 | shared.LogNetwork("SOCKS5 listener closed") |
| 921 | break |
| 922 | } |
| 923 | shared.LogErrorf("Failed to accept connection: %v", err) |
| 924 | continue |
| 925 | } |
| 926 | |
| 927 | go p.handleSOCKS5ConnectionWithConfigAndContext(ctx, conn, quicConn, bufferSize) |
| 928 | } |
| 929 | |
| 930 | return nil |
| 931 | } |
| 932 | |
| 933 | // StartWithConnManagerAndContext starts the SOCKS5 proxy server with a connection manager and context support |
| 934 | func (p *DefaultProxy) StartWithConnManagerAndContext(ctx context.Context, port int, cm *manager.ConnManager) error { |
no test coverage detected