Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

Commit

Permalink
feature: prohibit the IPv6 to communicate with supernode
Browse files Browse the repository at this point in the history
Signed-off-by: fengzixu <[email protected]>
  • Loading branch information
fengzixu committed Nov 13, 2019
1 parent 7300a6b commit 95dd1c9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pkg/httputils/http_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,9 @@ func CheckConnect(ip string, port int, timeout int) (localIP string, e error) {

var conn net.Conn
addr := fmt.Sprintf("%s:%d", ip, port)
if conn, e = net.DialTimeout("tcp", addr, t); e == nil {
// Just temporarily limit users can only use IP addr for IPv4 format.
// In the near future, if we want to support IPv6, we can revise logic as below.
if conn, e = net.DialTimeout("tcp4", addr, t); e == nil {
localIP = conn.LocalAddr().String()
conn.Close()
if idx := strings.LastIndexByte(localIP, ':'); idx >= 0 {
Expand Down
4 changes: 4 additions & 0 deletions pkg/httputils/http_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ func (s *HTTPUtilTestSuite) TestCheckConnect(c *check.C) {
ip, e := CheckConnect("127.0.0.1", s.port, 0)
c.Assert(e, check.IsNil)
c.Assert(ip, check.Equals, "127.0.0.1")

// Test IPv6
_, e = CheckConnect("[::1]", s.port, 0)
c.Assert(e, check.NotNil)
}

func (s *HTTPUtilTestSuite) TestGetRangeSE(c *check.C) {
Expand Down

0 comments on commit 95dd1c9

Please sign in to comment.