Commit bde95ec0 authored by Sushant Mahajan's avatar Sushant Mahajan

fixed conflicts

parents 575e9600 67cd155b
133059007 Sushant Mahajan 133059007 Sushant Mahajan
133050040 Harshit Pande 133050040 Harshit Pande
133050014 Bharath Radhakrishnan
...@@ -2,6 +2,12 @@ package main ...@@ -2,6 +2,12 @@ package main
import ( import (
"fmt" "fmt"
<<<<<<< HEAD
=======
"log"
"net"
"net/rpc"
>>>>>>> 67cd155b37c8122a61dfc1cfdaead50ea7f5729a
"os" "os"
"reflect" "reflect"
"strconv" "strconv"
...@@ -140,6 +146,34 @@ func start_rpc(this_server *ServerConfig) { ...@@ -140,6 +146,34 @@ func start_rpc(this_server *ServerConfig) {
//rpc.Register() //rpc.Register()
} }
type Args struct {
X int
}
type AppendEntries struct{}
func (t *AppendEntries) AppendEntriesRPC(args *Args, reply *int) error {
*reply = args.X
return nil
}
func initializeInterServerCommunication(this_server *ServerConfig) {
appendRpc := new(AppendEntries)
rpc.Register(appendRpc)
listener, e := net.Listen("tcp", ":"+strconv.Itoa(this_server.LogPort))
if e != nil {
log.Fatal("listen error:", e)
}
for {
if conn, err := listener.Accept(); err != nil {
log.Fatal("accept error: " + err.Error())
} else {
log.Printf("new connection established\n")
go rpc.ServeConn(conn)
}
}
}
func main() { func main() {
server_id, err := strconv.Atoi(os.Args[1]) server_id, err := strconv.Atoi(os.Args[1])
if err != nil { if err != nil {
...@@ -155,8 +189,7 @@ func main() { ...@@ -155,8 +189,7 @@ func main() {
fmt.Println(reflect.TypeOf(this_server)) fmt.Println(reflect.TypeOf(this_server))
fmt.Println(reflect.TypeOf(cluster_config)) fmt.Println(reflect.TypeOf(cluster_config))
initializeInterServerCommunication(this_server)
go start_rpc(this_server)
var dummy_input string var dummy_input string
fmt.Scanln(&dummy_input) fmt.Scanln(&dummy_input)
......
...@@ -14,19 +14,21 @@ const ( ...@@ -14,19 +14,21 @@ const (
NUM_SERVERS int = 5 NUM_SERVERS int = 5
) )
func TestServersCommunic() { func TestServersCommunic(i int) {
for i := 0; i < NUM_SERVERS; i++ {
cmd := exec.Command("go", "run", "replic_kvstore.go", strconv.Itoa(i+1), strconv.Itoa(NUM_SERVERS)) cmd := exec.Command("go", "run", "replic_kvstore.go", strconv.Itoa(i+1), strconv.Itoa(NUM_SERVERS))
out, err := cmd.CombinedOutput() out, err := cmd.CombinedOutput()
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
} }
fmt.Println(string(out)) fmt.Println(string(out))
}
} }
func main() { func main() {
TestServersCommunic() for i := 0; i < NUM_SERVERS; i++ {
go TestServersCommunic(i)
}
var dummy_input string var dummy_input string
fmt.Scanln(&dummy_input) fmt.Scanln(&dummy_input)
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment