diff options
| author | Paul Buetow <paul@buetow.org> | 2023-05-18 00:08:21 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2023-05-18 00:08:21 +0300 |
| commit | dde3bed148ea90cd505bf6fb67b08719ebc8933a (patch) | |
| tree | cdfb5ed57ff0cd09b531ea6dcf431dc216500118 | |
| parent | 8be9f0d9970f971ced7f1493295dd0ae08947ce9 (diff) | |
refactor
| -rw-r--r-- | README.md | 2 | ||||
| -rw-r--r-- | gorum.json | 9 | ||||
| -rw-r--r-- | internal/config.go | 10 | ||||
| -rw-r--r-- | internal/run.go | 4 | ||||
| -rw-r--r-- | internal/tcpserver.go | 4 |
5 files changed, 11 insertions, 18 deletions
@@ -1,3 +1,5 @@ # Gorum Gogios is a minimalistic quorum manager. + +This project is still under development! @@ -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) |
