Skip to content

Commit

Permalink
remove IsTCP() and IsUDP()
Browse files Browse the repository at this point in the history
  • Loading branch information
DarienRaymond committed Sep 19, 2016
1 parent 5291624 commit 9ade07d
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 20 deletions.
2 changes: 1 addition & 1 deletion app/router/rules/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (this *Router) ResolveIP(dest v2net.Destination) []v2net.Destination {
}
dests := make([]v2net.Destination, len(ips))
for idx, ip := range ips {
if dest.IsTCP() {
if dest.Network() == v2net.TCPNetwork {
dests[idx] = v2net.TCPDestination(v2net.IPAddress(ip), dest.Port())
} else {
dests[idx] = v2net.UDPDestination(v2net.IPAddress(ip), dest.Port())
Expand Down
4 changes: 2 additions & 2 deletions common/net/destination.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (dest *tcpDestination) Equals(another Destination) bool {
if dest == nil || another == nil {
return false
}
if !another.IsTCP() {
if another.Network() != TCPNetwork {
return false
}
return dest.Port() == another.Port() && dest.Address().Equals(another.Address())
Expand Down Expand Up @@ -124,7 +124,7 @@ func (dest *udpDestination) Equals(another Destination) bool {
if dest == nil || another == nil {
return false
}
if !another.IsUDP() {
if another.Network() != UDPNetwork {
return false
}
return dest.Port() == another.Port() && dest.Address().Equals(another.Address())
Expand Down
4 changes: 2 additions & 2 deletions proxy/freedom/freedom.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (this *FreedomConnection) ResolveIP(destination v2net.Destination) v2net.De

ip := ips[dice.Roll(len(ips))]
var newDest v2net.Destination
if destination.IsTCP() {
if destination.Network() == v2net.TCPNetwork {
newDest = v2net.TCPDestination(v2net.IPAddress(ip), destination.Port())
} else {
newDest = v2net.UDPDestination(v2net.IPAddress(ip), destination.Port())
Expand Down Expand Up @@ -112,7 +112,7 @@ func (this *FreedomConnection) Dispatch(destination v2net.Destination, payload *
var reader io.Reader = conn

timeout := this.timeout
if destination.IsUDP() {
if destination.Network() == v2net.UDPNetwork {
timeout = 16
}
if timeout > 0 {
Expand Down
2 changes: 1 addition & 1 deletion proxy/vmess/outbound/outbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (this *VMessOutboundHandler) Dispatch(target v2net.Destination, payload *al
log.Info("VMess|Outbound: Tunneling request to ", target, " via ", rec.Destination())

command := protocol.RequestCommandTCP
if target.IsUDP() {
if target.Network() == v2net.UDPNetwork {
command = protocol.RequestCommandUDP
}
request := &protocol.RequestHeader{
Expand Down
8 changes: 4 additions & 4 deletions testing/assert/destination.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,25 @@ type DestinationSubject struct {
}

func (this *DestinationSubject) IsTCP() {
if !this.value.IsTCP() {
if this.value.Network() != v2net.TCPNetwork {
this.Fail("is", "a TCP destination")
}
}

func (this *DestinationSubject) IsNotTCP() {
if this.value.IsTCP() {
if this.value.Network() == v2net.TCPNetwork {
this.Fail("is not", "a TCP destination")
}
}

func (this *DestinationSubject) IsUDP() {
if !this.value.IsUDP() {
if this.value.Network() != v2net.UDPNetwork {
this.Fail("is", "a UDP destination")
}
}

func (this *DestinationSubject) IsNotUDP() {
if this.value.IsUDP() {
if this.value.Network() == v2net.UDPNetwork {
this.Fail("is not", "a UDP destination")
}
}
Expand Down
9 changes: 2 additions & 7 deletions transport/internet/dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func Dial(src v2net.Address, dest v2net.Destination, settings *StreamSettings) (

var connection Connection
var err error
if dest.IsTCP() {
if dest.Network() == v2net.TCPNetwork {
switch {
case settings.IsCapableOf(StreamConnectionTypeTCP):
connection, err = TCPDialer(src, dest)
Expand All @@ -36,12 +36,7 @@ func Dial(src v2net.Address, dest v2net.Destination, settings *StreamSettings) (
case settings.IsCapableOf(StreamConnectionTypeWebSocket):
connection, err = WSDialer(src, dest)

/*Warning: Hours wasted: the following item must be last one
internet.StreamConnectionType have a default value of 1,
so the following attempt will catch all.
*/

// This check has to be the last one.
case settings.IsCapableOf(StreamConnectionTypeRawTCP):
connection, err = RawTCPDialer(src, dest)
default:
Expand Down
2 changes: 1 addition & 1 deletion transport/internet/system_dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (this *DefaultSystemDialer) Dial(src v2net.Address, dest v2net.Destination)
}
if src != nil && src != v2net.AnyIP {
var addr net.Addr
if dest.IsTCP() {
if dest.Network() == v2net.TCPNetwork {
addr = &net.TCPAddr{
IP: src.IP(),
Port: 0,
Expand Down
2 changes: 1 addition & 1 deletion transport/internet/tcp/dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func Dial(src v2net.Address, dest v2net.Destination) (internet.Connection, error
}
id := src.String() + "-" + dest.NetAddr()
var conn net.Conn
if dest.IsTCP() && effectiveConfig.ConnectionReuse {
if dest.Network() == v2net.TCPNetwork && effectiveConfig.ConnectionReuse {
conn = globalCache.Get(id)
}
if conn == nil {
Expand Down
2 changes: 1 addition & 1 deletion transport/internet/ws/dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func Dial(src v2net.Address, dest v2net.Destination) (internet.Connection, error
}
id := src.String() + "-" + dest.NetAddr()
var conn *wsconn
if dest.IsTCP() && effectiveConfig.ConnectionReuse {
if dest.Network() == v2net.TCPNetwork && effectiveConfig.ConnectionReuse {
connt := globalCache.Get(id)
if connt != nil {
conn = connt.(*wsconn)
Expand Down

0 comments on commit 9ade07d

Please sign in to comment.