summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2023-10-25 00:03:09 +0300
committerPaul Buetow <paul@buetow.org>2023-10-25 00:03:09 +0300
commit4df9dfc1e91ca64f553b5d5a76619155531aabd0 (patch)
tree593ae3db472ef71a7b8b8d283bffec7c8651b1cc /internal
parent8650dd57474e991515c93169151e6187205c9ff3 (diff)
test config works again after refactor
Diffstat (limited to 'internal')
-rw-r--r--internal/client/client.go10
-rw-r--r--internal/client/tcpclient.go8
-rw-r--r--internal/config/config.go10
3 files changed, 18 insertions, 10 deletions
diff --git a/internal/client/client.go b/internal/client/client.go
index f05fcba..0906386 100644
--- a/internal/client/client.go
+++ b/internal/client/client.go
@@ -15,7 +15,7 @@ func Start(ctx context.Context, conf config.Config, myVoteCh <-chan vote.Vote) {
nodeNum := 0
for _, node := range conf.Nodes {
- fanOut[nodeNum] = startConnection(ctx, node.Hostname)
+ fanOut[nodeNum] = startConnection(ctx, node.Address())
nodeNum++
}
@@ -46,14 +46,14 @@ func Start(ctx context.Context, conf config.Config, myVoteCh <-chan vote.Vote) {
}()
}
-func startConnection(ctx context.Context, node string) chan vote.Vote {
+func startConnection(ctx context.Context, address string) chan vote.Vote {
ch := make(chan vote.Vote, 1)
go func() {
for {
- log.Println("client: starting connection", node)
- if err := tcpClientRun(ctx, node, ch); err != nil {
- log.Println("client: not connected to node", node, "anymore:", err)
+ log.Println("client: starting connection", address)
+ if err := tcpClientRun(ctx, address, ch); err != nil {
+ log.Println("client: not connected to address", address, "anymore:", err)
}
select {
diff --git a/internal/client/tcpclient.go b/internal/client/tcpclient.go
index db4334f..a94bf89 100644
--- a/internal/client/tcpclient.go
+++ b/internal/client/tcpclient.go
@@ -10,8 +10,8 @@ import (
"codeberg.org/snonux/gorum/internal/vote"
)
-func tcpClientRun(ctx context.Context, node string, ch <-chan vote.Vote) error {
- conn, err := net.Dial("tcp", node)
+func tcpClientRun(ctx context.Context, address string, ch <-chan vote.Vote) error {
+ conn, err := net.Dial("tcp", address)
if err != nil {
return err
}
@@ -28,7 +28,7 @@ func tcpClientRun(ctx context.Context, node string, ch <-chan vote.Vote) error {
return err
}
- log.Println("tcpclient: sending", message, "to node", node)
+ log.Println("tcpclient: sending", message, "to address", address)
if err := iorw.WriteStr(conn, message); err != nil {
return err
}
@@ -38,6 +38,6 @@ func tcpClientRun(ctx context.Context, node string, ch <-chan vote.Vote) error {
return err
}
- log.Println("tcpclient: received", response, "from node", node)
+ log.Println("tcpclient: received", response, "from address", address)
}
}
diff --git a/internal/config/config.go b/internal/config/config.go
index b5030ee..f04aa57 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -19,6 +19,10 @@ type Node struct {
originalId string
}
+func (n Node) Address() string {
+ return fmt.Sprintf("%s:%d", n.Hostname, n.Port)
+}
+
type Config struct {
StateDir string
ScoreFile string
@@ -57,6 +61,10 @@ func NewFromConfigFile(configFile string) (Config, error) {
for id, node := range conf.Nodes {
log.Printf("adding node %s: %v", id, node)
node.originalId = id
+ if node.Alias != "" {
+ newNodes[node.Alias] = node
+ continue
+ }
newNodes[node.Hostname] = node
}
conf.Nodes = newNodes
@@ -181,5 +189,5 @@ func (conf Config) findNode(hostname string) (Node, error) {
}
}
- return Node{}, fmt.Errorf("node %s not found", hostname)
+ return Node{}, fmt.Errorf("node %s not found in %v", hostname, conf.Nodes)
}