2017-04-18 06:02:43 -04:00
|
|
|
// +build linux
|
|
|
|
|
|
|
|
package tcp_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2017-04-19 05:52:17 -04:00
|
|
|
"strings"
|
2017-04-18 06:02:43 -04:00
|
|
|
"testing"
|
|
|
|
|
2018-11-22 11:30:06 -05:00
|
|
|
"v2ray.com/core/common"
|
2017-04-18 06:02:43 -04:00
|
|
|
"v2ray.com/core/testing/servers/tcp"
|
2018-11-22 11:19:24 -05:00
|
|
|
"v2ray.com/core/transport/internet"
|
2017-04-18 06:12:17 -04:00
|
|
|
. "v2ray.com/core/transport/internet/tcp"
|
2017-10-24 11:36:42 -04:00
|
|
|
. "v2ray.com/ext/assert"
|
2017-04-18 06:02:43 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestGetOriginalDestination(t *testing.T) {
|
2017-10-24 10:15:35 -04:00
|
|
|
assert := With(t)
|
2017-04-18 06:02:43 -04:00
|
|
|
|
2017-04-18 06:12:17 -04:00
|
|
|
tcpServer := tcp.Server{}
|
2017-04-18 06:02:43 -04:00
|
|
|
dest, err := tcpServer.Start()
|
2019-02-02 16:19:30 -05:00
|
|
|
common.Must(err)
|
2017-04-18 06:02:43 -04:00
|
|
|
defer tcpServer.Close()
|
|
|
|
|
2018-11-22 11:30:06 -05:00
|
|
|
config, err := internet.ToMemoryStreamConfig(nil)
|
|
|
|
common.Must(err)
|
|
|
|
conn, err := Dial(context.Background(), dest, config)
|
2019-02-02 16:19:30 -05:00
|
|
|
common.Must(err)
|
2017-04-18 06:12:17 -04:00
|
|
|
defer conn.Close()
|
2017-04-18 06:02:43 -04:00
|
|
|
|
2017-04-19 05:52:17 -04:00
|
|
|
originalDest, err := GetOriginalDestination(conn)
|
2017-10-24 11:36:42 -04:00
|
|
|
assert(dest == originalDest || strings.Contains(err.Error(), "failed to call getsockopt"), IsTrue)
|
2017-04-18 06:02:43 -04:00
|
|
|
}
|