Skip to content

Commit

Permalink
Complete re-implementation of udp yyyar#153
Browse files Browse the repository at this point in the history
  • Loading branch information
illarion committed Aug 12, 2018
1 parent 785a3d8 commit af312cb
Show file tree
Hide file tree
Showing 7 changed files with 347 additions and 354 deletions.
2 changes: 1 addition & 1 deletion config/gobetween.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ bind = "localhost:4000"
protocol = "udp"

[servers.udpsample.udp]
max_responses = 0
max_responses = 1

[servers.udpsample.discovery]
kind = "static"
Expand Down
8 changes: 4 additions & 4 deletions src/core/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,19 @@ type UdpContext struct {
/**
* Current client remote address
*/
RemoteAddr net.UDPAddr
ClientAddr net.UDPAddr
}

func (u UdpContext) String() string {
return u.RemoteAddr.String()
return u.ClientAddr.String()
}

func (u UdpContext) Ip() net.IP {
return u.RemoteAddr.IP
return u.ClientAddr.IP
}

func (u UdpContext) Port() int {
return u.RemoteAddr.Port
return u.ClientAddr.Port
}

func (u UdpContext) Sni() string {
Expand Down
9 changes: 9 additions & 0 deletions src/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,15 @@ func prepareConfig(name string, server config.Server, defaults config.Connection
if server.BackendsTls != nil {
return config.Server{}, errors.New("backends_tls should not be enabled for udp protocol")
}

if server.Udp == nil {
server.Udp = &config.Udp{}
}

if server.Udp.MaxRequests == 0 && server.Udp.MaxResponses == 0 && server.ClientIdleTimeout == nil && server.BackendIdleTimeout == nil {
return config.Server{}, errors.New("udp protocol requires to specify at least one of (client|backend)_idle_timeout, udp.max_requests, udp.max_responses")
}

default:
return config.Server{}, errors.New("Not supported protocol " + server.Protocol)
}
Expand Down
Loading

0 comments on commit af312cb

Please sign in to comment.