Skip to content

Commit 0d329ac

Browse files
committed
Fix TCP connections not updating
1 parent 7f49fb6 commit 0d329ac

4 files changed

Lines changed: 14 additions & 7 deletions

File tree

backend/cmd/config.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ connections = "/backend"
1111
file_server = "/"
1212

1313
[vehicle]
14-
boards = ["BLCU"]
14+
boards = ["VCU"]
1515

1616
[vehicle.network]
1717
tcp_client_tag = "TCP_CLIENT"

backend/cmd/main.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,9 @@ func main() {
206206
}
207207
},
208208

209-
OnConnectionUpdate: func(target abstraction.TransportTarget, isConnected bool) {},
209+
OnConnectionUpdate: func(target abstraction.TransportTarget, isConnected bool) {
210+
connectionTransfer.Update(string(target), isConnected)
211+
},
210212
})
211213

212214
// Load and set packet decoder and encoder
@@ -221,7 +223,7 @@ func main() {
221223
}
222224

223225
// Start handling TCP client connections
224-
backendTcpClientAddr, err := net.ResolveTCPAddr("tcp", fmt.Sprintf("%s:%d", info.Addresses.Backend, info.Ports.TcpClient))
226+
backendTcpClientAddr, err := net.ResolveTCPAddr("tcp", fmt.Sprintf("%s:%d", info.Addresses.Backend.String(), info.Ports.TcpClient))
225227
if err != nil {
226228
panic("Failed to resolve local backend TCP client address")
227229
}
@@ -231,7 +233,7 @@ func main() {
231233
serverTargets[fmt.Sprintf("%s:%d", info.Addresses.Boards[board.Name], info.Ports.TcpClient)] = abstraction.TransportTarget(board.Name)
232234
continue
233235
}
234-
go transp.HandleClient(tcp.NewClient(backendTcpClientAddr), abstraction.TransportTarget(board.Name), "tcp", string(info.Addresses.Boards[board.Name]))
236+
go transp.HandleClient(tcp.NewClient(backendTcpClientAddr), abstraction.TransportTarget(board.Name), "tcp", fmt.Sprintf("%s:%d", info.Addresses.Boards[board.Name], info.Ports.TcpServer))
235237
}
236238

237239
// Start handling TCP server connections

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

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

33
import (
44
"context"
5+
"errors"
56
"fmt"
67
"net"
8+
"syscall"
79
"time"
810

911
"github.com/HyperloopUPV-H8/h9-backend/pkg/abstraction"
@@ -64,7 +66,7 @@ func NewClient(local net.Addr) ClientConfig {
6466

6567
Context: context.TODO(),
6668

67-
MaxRetries: 30,
69+
MaxRetries: -1,
6870
Backoff: NewExponBackoff(defaultBackoffMin, defaultBackoffExp, defaultBackoffMax),
6971
}
7072
}
@@ -82,7 +84,7 @@ func (config ClientConfig) Dial(network, remote string) (net.Conn, error) {
8284
return nil, config.Context.Err()
8385
}
8486

85-
if netErr, ok := err.(net.Error); !ok || !netErr.Timeout() {
87+
if netErr, ok := err.(net.Error); !errors.Is(err, syscall.ECONNREFUSED) && (!ok || !netErr.Timeout()) {
8688
return nil, err
8789
}
8890
time.Sleep(config.Backoff(config.CurrentRetries))

common-front/lib/store/connectionsStore.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ export const useConnectionsStore = create<ConnectionsStore>((set) => ({
4545
setConnections: (connections: Connection[]) => {
4646
set(state => ({
4747
...state,
48-
boards: connections
48+
connections: {
49+
...state.connections,
50+
boards: connections
51+
}
4952
}))
5053
}
5154
}))

0 commit comments

Comments
 (0)