summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2023-05-18 00:08:21 +0300
committerPaul Buetow <paul@buetow.org>2023-05-18 00:08:21 +0300
commitdde3bed148ea90cd505bf6fb67b08719ebc8933a (patch)
treecdfb5ed57ff0cd09b531ea6dcf431dc216500118
parent8be9f0d9970f971ced7f1493295dd0ae08947ce9 (diff)
refactor
-rw-r--r--README.md2
-rw-r--r--gorum.json9
-rw-r--r--internal/config.go10
-rw-r--r--internal/run.go4
-rw-r--r--internal/tcpserver.go4
5 files changed, 11 insertions, 18 deletions
diff --git a/README.md b/README.md
index 53b4516..0af0a57 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,5 @@
# Gorum
Gogios is a minimalistic quorum manager.
+
+This project is still under development!
diff --git a/gorum.json b/gorum.json
index 076b045..a2560d5 100644
--- a/gorum.json
+++ b/gorum.json
@@ -1,9 +1,8 @@
{
- "Hostname": "earth",
- "Port": 1234,
+ "Address": "earth:1234",
"Participants": [
- { "Hostname": "earth", "Port": 1234 },
- { "Hostname": "earth", "Port": 2341 },
- { "Hostname": "earth", "Port": 3412 }
+ "earth:1234",
+ "earth:2341",
+ "earth:3412"
]
}
diff --git a/internal/config.go b/internal/config.go
index c3fff26..1ed0bd8 100644
--- a/internal/config.go
+++ b/internal/config.go
@@ -6,15 +6,9 @@ import (
"os"
)
-type participant struct {
- Hostname string
- Port int
-}
-
type config struct {
- Hostname string
- Port int
- Participants []participant
+ Address string
+ Participants []string
}
func newConfig(configFile string) (config, error) {
diff --git a/internal/run.go b/internal/run.go
index 4904d33..4165f50 100644
--- a/internal/run.go
+++ b/internal/run.go
@@ -2,7 +2,6 @@ package internal
import (
"context"
- "fmt"
"log"
)
@@ -25,8 +24,7 @@ func Run(ctx context.Context, configFile string) {
}
}()
- address := fmt.Sprintf("%s:%d", config.Hostname, config.Port)
- if err := startTcpServer(ctx, address, ch); err != nil {
+ if err := startTcpServer(ctx, config.Address, ch); err != nil {
panic(err)
}
}
diff --git a/internal/tcpserver.go b/internal/tcpserver.go
index f264d9e..c65fb0b 100644
--- a/internal/tcpserver.go
+++ b/internal/tcpserver.go
@@ -28,7 +28,6 @@ func startTcpServer(ctx context.Context, address string, ch chan<- vote) error {
log.Printf("Client connected: %s\n", conn.RemoteAddr().String())
- // Handle the connection in a new goroutine
go handleConnection(ctx, conn, ch)
}
}
@@ -36,6 +35,7 @@ func startTcpServer(ctx context.Context, address string, ch chan<- vote) error {
func handleConnection(ctx context.Context, conn net.Conn, ch chan<- vote) {
defer conn.Close()
remoteAddr := conn.RemoteAddr().String()
+ // TODO: Reject remote connection when not in participant list!
log.Printf("Client %s connected\n", remoteAddr)
reader := bufio.NewReader(conn)
@@ -48,7 +48,7 @@ func handleConnection(ctx context.Context, conn net.Conn, ch chan<- vote) {
message, err := reader.ReadString('\n')
if err != nil {
log.Printf("Client %s disconnected: %s\n", remoteAddr, err.Error())
- break
+ return
}
log.Printf("Received message from %s: %s", remoteAddr, message)