Skip to content

Commit b9c5877

Browse files
Merge pull request #494 from Hyperloop-UPV/backend/tcp
Fix: tcp not starting backoff
2 parents 59abdd6 + 7354c83 commit b9c5877

File tree

13 files changed

+36
-86
lines changed

13 files changed

+36
-86
lines changed

backend/cmd/config.toml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
# 3. Toggle the Fault Propagation to your needs (true/false)
88
# 4. Check the TCP configuration and make sure to use the needed Keep Alive settings
99

10-
# Control Station general configuration
11-
[app]
12-
automatic_window_opening = "" # Leave blank to open no windows (<blank>, ethernet-view, control-station, both)
1310

1411
# Vehicle Configuration
1512
[vehicle]
@@ -40,13 +37,6 @@ keep_alive_ms = 1000 # Keep-alive interval in milliseconds
4037
ring_buffer_size = 64 # Size of the ring buffer for incoming packets (number of packets, not bytes)
4138
packet_chan_size = 16 # Size of the channel buffer
4239

43-
# TFTP Configuration
44-
[tftp]
45-
block_size = 131072 # TFTP block size in bytes (128kB)
46-
retries = 3 # Maximum number of retries before aborting transfer
47-
timeout_ms = 5000 # Timeout between retries in milliseconds
48-
backoff_factor = 2 # Backoff multiplier for retry delays
49-
enable_progress = true # Enable progress callbacks during transfers
5040

5141
# Logger Configuration
5242
[logging]

backend/cmd/dev-config.toml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
# 4. Check the TCP configuration and make sure to use the needed Keep Alive settings
1010

1111
# Control Station general configuration
12-
[app]
13-
automatic_window_opening = "" # Leave blank to open no windows (<blank>, ethernet-view, control-station, both)
1412

1513
# Vehicle Configuration
1614
[vehicle]
@@ -64,16 +62,6 @@ programable_boards = "/uploadableBoards"
6462
connections = "/backend"
6563
files = "/"
6664

67-
# TFTP Configuration
68-
[tftp]
69-
block_size = 512 # TFTP block size (512 or 1468 bytes)
70-
retries = 3 # Number of retries for TFTP operations
71-
timeout_ms = 5000 # Timeout for TFTP operations in milliseconds
72-
backoff_factor = 2 # Backoff factor for retries
73-
enable_progress = true # Enable progress updates during transfers
74-
75-
76-
7765
# Logging Configuration
7866
[logging]
7967
time_unit = "us" # Time unit for log timestamps (ns, us, ms, s)

backend/cmd/main.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,6 @@ func main() {
135135
}
136136
}
137137

138-
// Open browser tabs
139-
openBrowserTabs(config)
140-
141138
// Wait for interrupt signal to gracefully shutdown the backend
142139
interrupt := make(chan os.Signal, 1)
143140
signal.Notify(interrupt, os.Interrupt)

backend/cmd/orchestrator.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
"github.com/HyperloopUPV-H8/h9-backend/pkg/logger"
1616
data_logger "github.com/HyperloopUPV-H8/h9-backend/pkg/logger/data"
1717
order_logger "github.com/HyperloopUPV-H8/h9-backend/pkg/logger/order"
18-
"github.com/pkg/browser"
1918
trace "github.com/rs/zerolog/log"
2019
)
2120

@@ -148,16 +147,3 @@ func setUpLogger(config config.Config) (*logger.Logger, abstraction.SubloggersMa
148147
return loggerHandler, subloggers
149148

150149
}
151-
152-
func openBrowserTabs(config config.Config) {
153-
154-
switch config.App.AutomaticWindowOpening {
155-
case "ethernet-view":
156-
browser.OpenURL("http://" + config.Server["ethernet-view"].Addr)
157-
case "control-station":
158-
browser.OpenURL("http://" + config.Server["control-station"].Addr)
159-
case "both":
160-
browser.OpenURL("http://" + config.Server["ethernet-view"].Addr)
161-
browser.OpenURL("http://" + config.Server["control-station"].Addr)
162-
}
163-
}

backend/cmd/setup_transport.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,19 @@ func configureTCPClientTransport(
6464
i := 0 // count
6565

6666
// map of remote server addresses to transport targets for boards not present in vehicle config
67-
serverTargets := make(map[string]abstraction.TransportTarget)
6867
for _, board := range podData.Boards {
68+
69+
// Skip boards not in config.Vehicle.Boards to avoid unnecessary TCP clients and potential connection issues
6970
if !common.Contains(config.Vehicle.Boards, board.Name) {
70-
serverTargets[fmt.Sprintf("%s:%d", adj.Info.Addresses[board.Name], adj.Info.Ports[TcpClient])] = abstraction.TransportTarget(board.Name)
7171
continue
7272
}
73+
74+
// Resolve local TCP client address with incremental port to avoid conflicts
7375
backendTcpClientAddr, err := net.ResolveTCPAddr("tcp", fmt.Sprintf("%s:%d", adj.Info.Addresses[BACKEND], adj.Info.Ports[TcpClient]+uint16(i)))
7476
if err != nil {
75-
panic("Failed to resolve local backend TCP client address")
77+
trace.Fatal().Err(err).Msg("failed to resolve local backend TCP client address: " + err.Error())
7678
}
79+
7780
// Create TCP client config with custom parameters from config
7881
clientConfig := tcp.NewClientConfig(backendTcpClientAddr)
7982

backend/go.mod

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ require (
99
github.com/gorilla/websocket v1.5.0
1010
github.com/jmaralo/sntp v0.0.0-20240116111937-45a0a3419272
1111
github.com/pelletier/go-toml/v2 v2.0.7
12-
github.com/pin/tftp/v3 v3.0.0
13-
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c
1412
github.com/rs/zerolog v1.29.0
1513
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1
1614
)
@@ -41,6 +39,4 @@ require (
4139
gopkg.in/warnings.v0 v0.1.2 // indirect
4240
)
4341

44-
require (
45-
golang.org/x/net v0.38.0 // indirect
46-
)
42+
require golang.org/x/net v0.38.0 // indirect

backend/go.sum

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ github.com/elazarl/goproxy v0.0.0-20230808193330-2592e75ae04a h1:mATvB/9r/3gvcej
2323
github.com/elazarl/goproxy v0.0.0-20230808193330-2592e75ae04a/go.mod h1:Ro8st/ElPeALwNFlcTpWmkr6IoMFfkjXAvTHpevnDsM=
2424
github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc=
2525
github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ=
26-
github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
27-
github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw=
2826
github.com/gliderlabs/ssh v0.3.7 h1:iV3Bqi942d9huXnzEF2Mt+CY9gLu8DNM4Obd+8bODRE=
2927
github.com/gliderlabs/ssh v0.3.7/go.mod h1:zpHEXBstFnQYtGnB8k8kQLol82umzn/2/snG7alWVD8=
3028
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 h1:+zs/tPmkDkHx3U66DAb0lQFJrpS6731Oaa12ikc+DiI=
@@ -46,8 +44,6 @@ github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
4644
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
4745
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
4846
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
49-
github.com/hashicorp/go-version v1.7.0 h1:5tqGy27NaOTB8yJKUZELlFAS/LTKJkrmONwQKeRZfjY=
50-
github.com/hashicorp/go-version v1.7.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
5147
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
5248
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
5349
github.com/jmaralo/sntp v0.0.0-20240116111937-45a0a3419272 h1:dtQzdBn2P781UxyDPZd1tv4QE29ffpnmJ15qBkXHypY=
@@ -72,12 +68,8 @@ github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI=
7268
github.com/onsi/gomega v1.27.10/go.mod h1:RsS8tutOdbdgzbPtzzATp12yT7kM5I5aElG3evPbQ0M=
7369
github.com/pelletier/go-toml/v2 v2.0.7 h1:muncTPStnKRos5dpVKULv2FVd4bMOhNePj9CjgDb8Us=
7470
github.com/pelletier/go-toml/v2 v2.0.7/go.mod h1:eumQOmlWiOPt5WriQQqoM5y18pDHwha2N+QD+EUNTek=
75-
github.com/pin/tftp/v3 v3.0.0 h1:o9cQpmWBSbgiaYXuN+qJAB12XBIv4dT7OuOONucn2l0=
76-
github.com/pin/tftp/v3 v3.0.0/go.mod h1:xwQaN4viYL019tM4i8iecm++5cGxSqen6AJEOEyEI0w=
7771
github.com/pjbgf/sha1cd v0.3.0 h1:4D5XXmUUBUl/xQ6IjCkEAbqXskkq/4O7LmGn0AqMDs4=
7872
github.com/pjbgf/sha1cd v0.3.0/go.mod h1:nZ1rrWOcGJ5uZgEEVL1VUM9iRQiZvWdbZjkKyFzPPsI=
79-
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c h1:+mdjkGKdHQG3305AYmdv1U2eRNDiU2ErMBj1gwrq8eQ=
80-
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c/go.mod h1:7rwL4CYBLnjLxUqIJNnCWiEdr3bn6IUYi15bNlnbCCU=
8173
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
8274
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
8375
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
@@ -123,7 +115,6 @@ golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc=
123115
golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
124116
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
125117
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
126-
golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
127118
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
128119
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
129120
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
@@ -150,7 +141,6 @@ golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBc
150141
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
151142
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
152143
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
153-
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
154144
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
155145
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
156146
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=

backend/internal/config/config_types.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ import (
66
"github.com/HyperloopUPV-H8/h9-backend/pkg/logger"
77
)
88

9-
type App struct {
10-
AutomaticWindowOpening string `toml:"automatic_window_opening"`
11-
}
12-
139
type Adj struct {
1410
Branch string `toml:"branch"`
1511
Validate bool `toml:"validate"`
@@ -19,14 +15,6 @@ type Transport struct {
1915
PropagateFault bool `toml:"propagate_fault"`
2016
}
2117

22-
type TFTP struct {
23-
BlockSize int `toml:"block_size"`
24-
Retries int `toml:"retries"`
25-
TimeoutMs int `toml:"timeout_ms"`
26-
BackoffFactor int `toml:"backoff_factor"`
27-
EnableProgress bool `toml:"enable_progress"`
28-
}
29-
3018
type TCP struct {
3119
BackoffMinMs int `toml:"backoff_min_ms"`
3220
BackoffMaxMs int `toml:"backoff_max_ms"`
@@ -47,12 +35,10 @@ type Logging struct {
4735
}
4836

4937
type Config struct {
50-
App App
5138
Vehicle vehicle.Config
5239
Server server.Config
5340
Adj Adj
5441
Transport Transport
55-
TFTP TFTP
5642
TCP TCP
5743
UDP UDP
5844
Logging Logging

backend/pkg/transport/network/tcp/client.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
package tcp
22

33
import (
4-
"errors"
54
"fmt"
65
"net"
7-
"syscall"
86
"time"
97

108
"github.com/rs/zerolog"
@@ -38,6 +36,7 @@ func (client *Client) Dial() (net.Conn, error) {
3836

3937
var err error
4038
var conn net.Conn
39+
client.currentRetries = 0
4140
client.logger.Info().Msg("dialing")
4241

4342
for client.config.MaxConnectionRetries <= 0 || client.currentRetries < client.config.MaxConnectionRetries {
@@ -64,8 +63,8 @@ func (client *Client) Dial() (net.Conn, error) {
6463
return nil, client.config.Context.Err()
6564
}
6665

67-
// Check if we should retry this error
68-
if netErr, ok := err.(net.Error); !client.config.TryReconnect || (!errors.Is(err, syscall.ECONNREFUSED) && (!ok || !netErr.Timeout())) {
66+
// If reconnection is disabled, bail out immediately on any error
67+
if !client.config.TryReconnect {
6968
client.logger.Error().Stack().Err(err).Msg("failed with non-retryable error")
7069
return nil, err
7170
}

backend/pkg/transport/network/tcp/config.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,13 @@ func NewClientConfig(laddr net.Addr) ClientConfig {
2424
Dialer: net.Dialer{
2525
Timeout: time.Second,
2626
LocalAddr: laddr,
27-
KeepAlive: time.Second, // Going under 1 second won't work in most systems
27+
KeepAlive: -1, // managed via KeepAliveConfig
28+
KeepAliveConfig: net.KeepAliveConfig{
29+
Enable: true,
30+
Idle: time.Second,
31+
Interval: time.Second,
32+
Count: 3,
33+
},
2834
},
2935

3036
Context: context.TODO(),
@@ -69,7 +75,13 @@ type ServerConfig struct {
6975
func NewServerConfig() ServerConfig {
7076
return ServerConfig{
7177
ListenConfig: net.ListenConfig{
72-
KeepAlive: time.Second,
78+
KeepAlive: -1, // managed via KeepAliveConfig
79+
KeepAliveConfig: net.KeepAliveConfig{
80+
Enable: true,
81+
Idle: time.Second,
82+
Interval: time.Second,
83+
Count: 3,
84+
},
7385
},
7486
Context: context.TODO(),
7587
}

0 commit comments

Comments
 (0)