Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GRA-1444: Proxy only required connections #2149

Merged
merged 3 commits into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion controllers/ext_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ func getExtClientConf(w http.ResponseWriter, r *http.Request) {
if network.DefaultKeepalive != 0 {
keepalive = "PersistentKeepalive = " + strconv.Itoa(int(network.DefaultKeepalive))
}
gwendpoint := host.EndpointIP.String() + ":" + strconv.Itoa(logic.GetPeerListenPort(host))
gwendpoint := host.EndpointIP.String() + ":" + strconv.Itoa(host.ListenPort)
newAllowedIPs := network.AddressRange
if newAllowedIPs != "" && network.AddressRange6 != "" {
newAllowedIPs += ","
Expand Down
13 changes: 6 additions & 7 deletions controllers/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func createHostRelay(w http.ResponseWriter, r *http.Request) {
return
}
relay.HostID = params["hostid"]
relayHost, _, err := logic.CreateHostRelay(relay)
relayHost, relayedHosts, err := logic.CreateHostRelay(relay)
if err != nil {
logger.Log(0, r.Header.Get("user"),
fmt.Sprintf("failed to create relay on host [%s]: %v", relay.HostID, err))
Expand All @@ -131,15 +131,14 @@ func createHostRelay(w http.ResponseWriter, r *http.Request) {
}
logger.Log(1, r.Header.Get("user"), "created relay on host", relay.HostID)
go func(relayHostID string) {
relatedhosts := logic.GetRelatedHosts(relayHostID)
for _, relatedHost := range relatedhosts {
relatedHost.ProxyEnabled = true
logic.UpsertHost(&relatedHost)
for _, relayedHost := range relayedHosts {
relayedHost.ProxyEnabled = true
logic.UpsertHost(&relayedHost)
if err := mq.HostUpdate(&models.HostUpdate{
Action: models.UpdateHost,
Host: relatedHost,
Host: relayedHost,
}); err != nil {
logger.Log(0, "failed to send host update: ", relatedHost.ID.String(), err.Error())
logger.Log(0, "failed to send host update: ", relayedHost.ID.String(), err.Error())
}
}
if err := mq.PublishPeerUpdate(); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion logic/peers.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func GetPeerUpdateForHost(ctx context.Context, network string, host *models.Host
}
peerConfig.Endpoint = &net.UDPAddr{
IP: peerHost.EndpointIP,
Port: GetPeerListenPort(peerHost),
Port: peerHost.ListenPort,
}

if uselocal {
Expand Down
14 changes: 9 additions & 5 deletions mq/publishers.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,19 @@ func PublishSingleHostPeerUpdate(ctx context.Context, host *models.Host, deleted
if len(peerUpdate.Peers) == 0 { // no peers to send
return nil
}
proxyUpdate, err := logic.GetProxyUpdateForHost(ctx, host)
if err != nil {
return err
}
proxyUpdate.Server = servercfg.GetServer()
if host.ProxyEnabled {
proxyUpdate, err := logic.GetProxyUpdateForHost(ctx, host)
if err != nil {
return err
}
proxyUpdate.Action = models.ProxyUpdate
peerUpdate.ProxyUpdate = proxyUpdate
} else {
proxyUpdate.Action = models.NoProxy
}

peerUpdate.ProxyUpdate = proxyUpdate

data, err := json.Marshal(&peerUpdate)
if err != nil {
return err
Expand Down