diff options
Diffstat (limited to 'internal/client')
| -rw-r--r-- | internal/client/client.go | 15 | ||||
| -rw-r--r-- | internal/client/tcpclient.go | 11 |
2 files changed, 16 insertions, 10 deletions
diff --git a/internal/client/client.go b/internal/client/client.go index 91d64e2..3cb2775 100644 --- a/internal/client/client.go +++ b/internal/client/client.go @@ -6,11 +6,12 @@ import ( "time" "codeberg.org/snonux/gorum/internal/config" + "codeberg.org/snonux/gorum/internal/vote" ) -func Start(ctx context.Context, conf config.Config, liveNodesCh <-chan []string) { +func Start(ctx context.Context, conf config.Config, myVoteCh <-chan vote.Vote) { log.Println("client: starting") - fanOut := make([]chan []string, len(conf.Nodes)) + fanOut := make([]chan vote.Vote, len(conf.Nodes)) for i, node := range conf.Nodes { fanOut[i] = startConnection(ctx, node) @@ -25,8 +26,8 @@ func Start(ctx context.Context, conf config.Config, liveNodesCh <-chan []string) for { select { - case liveNodes := <-liveNodesCh: - log.Printf("client: notifying live nodes %v to all partner nodes", liveNodes) + case myVote := <-myVoteCh: + log.Printf("client: notifying live nodes %v to all partner nodes", myVote) for _, ch := range fanOut { // First, clear previous element of the channel, if any select { @@ -34,7 +35,7 @@ func Start(ctx context.Context, conf config.Config, liveNodesCh <-chan []string) default: } // Now, update channel with the new live nodes. - ch <- liveNodes + ch <- myVote } case <-ctx.Done(): return @@ -43,8 +44,8 @@ func Start(ctx context.Context, conf config.Config, liveNodesCh <-chan []string) }() } -func startConnection(ctx context.Context, node string) chan []string { - ch := make(chan []string, 1) +func startConnection(ctx context.Context, node string) chan vote.Vote { + ch := make(chan vote.Vote, 1) go func() { for { diff --git a/internal/client/tcpclient.go b/internal/client/tcpclient.go index 58004c7..83cb3b6 100644 --- a/internal/client/tcpclient.go +++ b/internal/client/tcpclient.go @@ -6,10 +6,11 @@ import ( "io/ioutil" "log" "net" - "strings" + + "codeberg.org/snonux/gorum/internal/vote" ) -func tcpClientRun(ctx context.Context, node string, ch <-chan []string) error { +func tcpClientRun(ctx context.Context, node string, ch <-chan vote.Vote) error { conn, err := net.Dial("tcp", node) if err != nil { return err @@ -22,7 +23,11 @@ func tcpClientRun(ctx context.Context, node string, ch <-chan []string) error { return fmt.Errorf("channel closed - breaking tcpClientRun loop") } - message := strings.Join(votes, " ") + message, err := votes.ToJSON() + if err != nil { + return err + } + log.Println("tcpclient: sending", message, "to node", node) _, err = conn.Write([]byte(message)) if err != nil { |
