Chore: logging real listen port (#1492)

This commit is contained in:
gVisor bot 2021-07-19 14:07:51 +08:00
parent f01d4cbb4c
commit 6b418d4369
8 changed files with 32 additions and 24 deletions

View file

@ -3,6 +3,7 @@ package route
import ( import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"net"
"net/http" "net/http"
"strings" "strings"
"time" "time"
@ -81,10 +82,15 @@ func Start(addr string, secret string) {
}) })
} }
log.Infoln("RESTful API listening at: %s", addr) l, err := net.Listen("tcp", addr)
err := http.ListenAndServe(addr, r)
if err != nil { if err != nil {
log.Errorln("External controller error: %s", err.Error()) log.Errorln("External controller listen error: %s", err)
return
}
serverAddr = l.Addr().String()
log.Infoln("RESTful API listening at: %s", serverAddr)
if err = http.Serve(l, r); err != nil {
log.Errorln("External controller serve error: %s", err)
} }
} }

View file

@ -10,7 +10,6 @@ import (
type Listener struct { type Listener struct {
listener net.Listener listener net.Listener
address string
closed bool closed bool
} }
@ -31,7 +30,6 @@ func NewWithAuthenticate(addr string, in chan<- C.ConnContext, authenticate bool
hl := &Listener{ hl := &Listener{
listener: l, listener: l,
address: addr,
} }
go func() { go func() {
for { for {
@ -55,5 +53,5 @@ func (l *Listener) Close() {
} }
func (l *Listener) Address() string { func (l *Listener) Address() string {
return l.address return l.listener.Addr().String()
} }

View file

@ -15,7 +15,6 @@ import (
type Listener struct { type Listener struct {
listener net.Listener listener net.Listener
address string
closed bool closed bool
cache *cache.Cache cache *cache.Cache
} }
@ -26,7 +25,10 @@ func New(addr string, in chan<- C.ConnContext) (*Listener, error) {
return nil, err return nil, err
} }
ml := &Listener{l, addr, false, cache.New(30 * time.Second)} ml := &Listener{
listener: l,
cache: cache.New(30 * time.Second),
}
go func() { go func() {
for { for {
c, err := ml.listener.Accept() c, err := ml.listener.Accept()
@ -49,7 +51,7 @@ func (l *Listener) Close() {
} }
func (l *Listener) Address() string { func (l *Listener) Address() string {
return l.address return l.listener.Addr().String()
} }
func handleConn(conn net.Conn, in chan<- C.ConnContext, cache *cache.Cache) { func handleConn(conn net.Conn, in chan<- C.ConnContext, cache *cache.Cache) {

View file

@ -9,7 +9,6 @@ import (
type Listener struct { type Listener struct {
listener net.Listener listener net.Listener
address string
closed bool closed bool
} }
@ -18,7 +17,9 @@ func New(addr string, in chan<- C.ConnContext) (*Listener, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
rl := &Listener{l, addr, false} rl := &Listener{
listener: l,
}
go func() { go func() {
for { for {
@ -42,7 +43,7 @@ func (l *Listener) Close() {
} }
func (l *Listener) Address() string { func (l *Listener) Address() string {
return l.address return l.listener.Addr().String()
} }
func handleRedir(conn net.Conn, in chan<- C.ConnContext) { func handleRedir(conn net.Conn, in chan<- C.ConnContext) {

View file

@ -15,7 +15,6 @@ import (
type Listener struct { type Listener struct {
listener net.Listener listener net.Listener
address string
closed bool closed bool
} }
@ -25,7 +24,9 @@ func New(addr string, in chan<- C.ConnContext) (*Listener, error) {
return nil, err return nil, err
} }
sl := &Listener{l, addr, false} sl := &Listener{
listener: l,
}
go func() { go func() {
for { for {
c, err := l.Accept() c, err := l.Accept()
@ -48,7 +49,7 @@ func (l *Listener) Close() {
} }
func (l *Listener) Address() string { func (l *Listener) Address() string {
return l.address return l.listener.Addr().String()
} }
func handleSocks(conn net.Conn, in chan<- C.ConnContext) { func handleSocks(conn net.Conn, in chan<- C.ConnContext) {

View file

@ -13,7 +13,6 @@ import (
type UDPListener struct { type UDPListener struct {
packetConn net.PacketConn packetConn net.PacketConn
address string
closed bool closed bool
} }
@ -27,7 +26,9 @@ func NewUDP(addr string, in chan<- *inbound.PacketAdapter) (*UDPListener, error)
log.Warnln("Failed to Reuse UDP Address: %s", err) log.Warnln("Failed to Reuse UDP Address: %s", err)
} }
sl := &UDPListener{l, addr, false} sl := &UDPListener{
packetConn: l,
}
go func() { go func() {
for { for {
buf := pool.Get(pool.RelayBufferSize) buf := pool.Get(pool.RelayBufferSize)
@ -52,7 +53,7 @@ func (l *UDPListener) Close() error {
} }
func (l *UDPListener) Address() string { func (l *UDPListener) Address() string {
return l.address return l.packetConn.LocalAddr().String()
} }
func handleSocksUDP(pc net.PacketConn, in chan<- *inbound.PacketAdapter, buf []byte, addr net.Addr) { func handleSocksUDP(pc net.PacketConn, in chan<- *inbound.PacketAdapter, buf []byte, addr net.Addr) {

View file

@ -10,7 +10,6 @@ import (
type Listener struct { type Listener struct {
listener net.Listener listener net.Listener
address string
closed bool closed bool
} }
@ -33,7 +32,6 @@ func New(addr string, in chan<- C.ConnContext) (*Listener, error) {
rl := &Listener{ rl := &Listener{
listener: l, listener: l,
address: addr,
} }
go func() { go func() {
@ -58,7 +56,7 @@ func (l *Listener) Close() {
} }
func (l *Listener) Address() string { func (l *Listener) Address() string {
return l.address return l.listener.Addr().String()
} }
func (l *Listener) handleTProxy(conn net.Conn, in chan<- C.ConnContext) { func (l *Listener) handleTProxy(conn net.Conn, in chan<- C.ConnContext) {

View file

@ -11,7 +11,6 @@ import (
type UDPListener struct { type UDPListener struct {
packetConn net.PacketConn packetConn net.PacketConn
address string
closed bool closed bool
} }
@ -21,7 +20,9 @@ func NewUDP(addr string, in chan<- *inbound.PacketAdapter) (*UDPListener, error)
return nil, err return nil, err
} }
rl := &UDPListener{l, addr, false} rl := &UDPListener{
packetConn: l,
}
c := l.(*net.UDPConn) c := l.(*net.UDPConn)
@ -65,7 +66,7 @@ func (l *UDPListener) Close() error {
} }
func (l *UDPListener) Address() string { func (l *UDPListener) Address() string {
return l.address return l.packetConn.LocalAddr().String()
} }
func handlePacketConn(pc net.PacketConn, in chan<- *inbound.PacketAdapter, buf []byte, lAddr *net.UDPAddr, rAddr *net.UDPAddr) { func handlePacketConn(pc net.PacketConn, in chan<- *inbound.PacketAdapter, buf []byte, lAddr *net.UDPAddr, rAddr *net.UDPAddr) {