mirror of
https://github.com/v2fly/v2ray-core.git
synced 2026-01-01 06:55:25 -05:00
refactor common/net.Port
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
package json
|
||||
|
||||
import (
|
||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||
v2netjson "github.com/v2ray/v2ray-core/common/net/json"
|
||||
"github.com/v2ray/v2ray-core/proxy/common/config/json"
|
||||
)
|
||||
|
||||
type DokodemoConfig struct {
|
||||
Host string `json:"address"`
|
||||
Port int `json:"port"`
|
||||
Port v2net.Port `json:"port"`
|
||||
Network *v2netjson.NetworkList `json:"network"`
|
||||
Timeout int `json:"timeout"`
|
||||
}
|
||||
|
||||
@@ -27,14 +27,14 @@ func NewDokodemoDoor(dispatcher app.PacketDispatcher, config *json.DokodemoConfi
|
||||
}
|
||||
ip := net.ParseIP(config.Host)
|
||||
if ip != nil {
|
||||
d.address = v2net.IPAddress(ip, uint16(config.Port))
|
||||
d.address = v2net.IPAddress(ip, config.Port)
|
||||
} else {
|
||||
d.address = v2net.DomainAddress(config.Host, uint16(config.Port))
|
||||
d.address = v2net.DomainAddress(config.Host, config.Port)
|
||||
}
|
||||
return d
|
||||
}
|
||||
|
||||
func (this *DokodemoDoor) Listen(port uint16) error {
|
||||
func (this *DokodemoDoor) Listen(port v2net.Port) error {
|
||||
this.accepting = true
|
||||
|
||||
if this.config.Network.HasNetwork(v2net.TCPNetwork) {
|
||||
@@ -52,7 +52,7 @@ func (this *DokodemoDoor) Listen(port uint16) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (this *DokodemoDoor) ListenUDP(port uint16) error {
|
||||
func (this *DokodemoDoor) ListenUDP(port v2net.Port) error {
|
||||
udpConn, err := net.ListenUDP("udp", &net.UDPAddr{
|
||||
IP: []byte{0, 0, 0, 0},
|
||||
Port: int(port),
|
||||
@@ -88,7 +88,7 @@ func (this *DokodemoDoor) handleUDPPackets(udpConn *net.UDPConn) {
|
||||
}
|
||||
}
|
||||
|
||||
func (this *DokodemoDoor) ListenTCP(port uint16) error {
|
||||
func (this *DokodemoDoor) ListenTCP(port v2net.Port) error {
|
||||
tcpListener, err := net.ListenTCP("tcp", &net.TCPAddr{
|
||||
IP: []byte{0, 0, 0, 0},
|
||||
Port: int(port),
|
||||
|
||||
@@ -43,7 +43,7 @@ func TestDokodemoTCP(t *testing.T) {
|
||||
ProtocolValue: "dokodemo-door",
|
||||
SettingsValue: &json.DokodemoConfig{
|
||||
Host: "127.0.0.1",
|
||||
Port: int(port),
|
||||
Port: port,
|
||||
Network: &networkList,
|
||||
Timeout: 0,
|
||||
},
|
||||
@@ -105,7 +105,7 @@ func TestDokodemoUDP(t *testing.T) {
|
||||
ProtocolValue: "dokodemo-door",
|
||||
SettingsValue: &json.DokodemoConfig{
|
||||
Host: "127.0.0.1",
|
||||
Port: int(port),
|
||||
Port: port,
|
||||
Network: &networkList,
|
||||
Timeout: 0,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user