Skip to content

Commit

Permalink
consistency
Browse files Browse the repository at this point in the history
* cli talekfrontend / talekreplica use server.Run()
* integrate #82 to make sure tests pass
* remove `http.Client` from rpc_call interface
  • Loading branch information
willscott committed Nov 18, 2017
1 parent 4c00c8b commit 973d2a5
Show file tree
Hide file tree
Showing 34 changed files with 141 additions and 755 deletions.
13 changes: 13 additions & 0 deletions cli/clinfo/fallback.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package main

import (
"log"
)

func fallback() {
log.Fatal("Can't run CLinfo without openCL tag")
}

func main() {
return
}
2 changes: 1 addition & 1 deletion cli/clinfo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,6 @@ func StatInfo() {
}
}

func main() {
func init() {
StatInfo()
}
11 changes: 1 addition & 10 deletions cli/talekfrontend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package main

import (
"log"
"net"
"net/http"
"os"
"os/signal"

Expand Down Expand Up @@ -42,18 +40,11 @@ func main() {

f := server.NewFrontendServer("Talek Frontend", serverConfig, config.TrustDomains)
f.Frontend.Verbose = *verbose

bindAddr, err := net.ResolveTCPAddr("ip", *listen)
if err != nil {
log.Printf("Couldn't resolve address '%s': %v\n", *listen, err)
return
}
listener, err := net.ListenTCP("ip", bindAddr)
listener, err := f.Run(*listen)
if err != nil {
log.Printf("Couldn't listen to frontend address: %v\n", err)
return
}
go http.Serve(listener, f)

log.Println("Running.")

Expand Down
11 changes: 1 addition & 10 deletions cli/talekreplica/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"encoding/json"
"io/ioutil"
"log"
"net"
"net/http"
"os"
"os/signal"
"time"
Expand Down Expand Up @@ -74,18 +72,11 @@ func main() {
log.Printf("serverConfig.Config=%#+v\n", serverConfig.Config)

r := server.NewReplicaServer(serverConfig.TrustDomain.Name, *backing, serverConfig)

bindAddr, err := net.ResolveTCPAddr("ip", *listen)
if err != nil {
log.Printf("Couldn't resolve frontend address '%s': %v\n", *listen, err)
return
}
listener, err := net.ListenTCP("ip", bindAddr)
listener, err := r.Run(*listen)
if err != nil {
log.Printf("Couldn't listen to frontend address: %v\n", err)
return
}
go http.Serve(listener, r)

log.Println("Running.")

Expand Down
10 changes: 4 additions & 6 deletions common/frontend_rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package common

import (
"log"
"net/http"
"os"
)

Expand All @@ -12,7 +11,6 @@ type FrontendRPC struct {
name string
address string
methodPrefix string
*http.Client
}

// NewFrontendRPC instantiates a LeaderRPC stub
Expand All @@ -35,25 +33,25 @@ func (f *FrontendRPC) GetName(_ *interface{}, reply *string) error {
// GetConfig tells the client about current config.
func (f *FrontendRPC) GetConfig(_ *interface{}, reply *Config) error {
var args interface{}
err := RPCCall(f.Client, f.address, f.methodPrefix+".GetConfig", &args, reply)
err := RPCCall(f.address, f.methodPrefix+".GetConfig", &args, reply)
return err
}

func (f *FrontendRPC) Write(args *WriteArgs, reply *WriteReply) error {
//l.log.Printf("Write: enter\n")
err := RPCCall(f.Client, f.address, f.methodPrefix+".Write", args, reply)
err := RPCCall(f.address, f.methodPrefix+".Write", args, reply)
return err
}

func (f *FrontendRPC) Read(args *EncodedReadArgs, reply *ReadReply) error {
//l.log.Printf("Read: enter\n")
err := RPCCall(f.Client, f.address, f.methodPrefix+".Read", args, reply)
err := RPCCall(f.address, f.methodPrefix+".Read", args, reply)
return err
}

// GetUpdates provides the global interest vector.
func (f *FrontendRPC) GetUpdates(args *GetUpdatesArgs, reply *GetUpdatesReply) error {
//l.log.Printf("GetUpdates: enter\n")
err := RPCCall(f.Client, f.address, f.methodPrefix+".GetUpdates", args, reply)
err := RPCCall(f.address, f.methodPrefix+".GetUpdates", args, reply)
return err
}
8 changes: 3 additions & 5 deletions common/replica_rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package common

import (
"log"
"net/http"
"os"
)

Expand All @@ -12,7 +11,6 @@ type ReplicaRPC struct {
name string
address string
methodPrefix string
*http.Client
}

// NewReplicaRPC creates a new ReplicaRPC
Expand All @@ -33,20 +31,20 @@ func NewReplicaRPC(name string, config *TrustDomainConfig) *ReplicaRPC {

func (r *ReplicaRPC) Write(args *ReplicaWriteArgs, reply *ReplicaWriteReply) error {
//f.log.Printf("Write: enter\n")
err := RPCCall(r.Client, r.address, r.methodPrefix+".Write", args, reply)
err := RPCCall(r.address, r.methodPrefix+".Write", args, reply)
return err
}

// BatchRead performs a set of PIR reads.
func (r *ReplicaRPC) BatchRead(args *BatchReadRequest, reply *BatchReadReply) error {
//f.log.Printf("BatchRead: enter\n")
err := RPCCall(r.Client, r.address, r.methodPrefix+".BatchRead", args, reply)
err := RPCCall(r.address, r.methodPrefix+".BatchRead", args, reply)
return err
}

// GetUpdates provies the most recent set of global interest vector changes.
func (r *ReplicaRPC) GetUpdates(args *GetUpdatesArgs, reply *GetUpdatesReply) error {
//f.log.Printf("GetUpdates: enter\n")
err := RPCCall(r.Client, r.address, r.methodPrefix+".GetUpdates", args, reply)
err := RPCCall(r.address, r.methodPrefix+".GetUpdates", args, reply)
return err
}
7 changes: 2 additions & 5 deletions common/rpc_call.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@ import (
)

// RPCCall Makes a JSON RPC client.
func RPCCall(client *http.Client, address string, methodName string, args interface{}, reply interface{}) error {
func RPCCall(address string, methodName string, args interface{}, reply interface{}) error {
var err error
if client == nil {
client = &http.Client{}
}

// Encode arguments
message, err := json.EncodeClientRequest(methodName, args)
Expand All @@ -28,7 +25,7 @@ func RPCCall(client *http.Client, address string, methodName string, args interf
req.Header.Set("Content-Type", "application/json")

// Do RPC
resp, err := client.Do(req)
resp, err := (&http.Client{}).Do(req)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pir/pircl.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//+build !noopencl,!travis
//+build +opencl,!travis

package pir

Expand Down
2 changes: 1 addition & 1 deletion pir/pircl/context_cl.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//+build !noopencl,!travis
//+build +opencl,!travis

package pircl

Expand Down
2 changes: 1 addition & 1 deletion pir/pircl/shard_cl.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//+build !noopencl,!travis
//+build +opencl,!travis

package pircl

Expand Down
2 changes: 1 addition & 1 deletion pir/pircl/shard_cl_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//+build !noopencl,!travis
//+build +opencl,!travis

package pircl

Expand Down
2 changes: 1 addition & 1 deletion pir/pircuda.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//+build !nocuda,!travis
//+build +cuda,!travis

package pir

Expand Down
2 changes: 1 addition & 1 deletion pir/pircuda/context_cuda.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//+build !nocuda,!travis
//+build +cuda,!travis

package pircuda

Expand Down
2 changes: 1 addition & 1 deletion pir/pircuda/shard_cuda.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//+build !nocuda,!travis
//+build +cuda,!travis

package pircuda

Expand Down
2 changes: 1 addition & 1 deletion pir/pircuda/shard_cuda_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//+build !nocuda,!travis
//+build +cuda,!travis

package pircuda

Expand Down
10 changes: 5 additions & 5 deletions protocol/coordinator/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,31 @@ func (c *Client) Close() error {
// GetInfo returns info about this server
func (c *Client) GetInfo(_ *interface{}, reply *GetInfoReply) error {
var args interface{}
c.lastErr = common.RPCCall(nil, c.address, "Coordinator.GetInfo", &args, reply)
c.lastErr = common.RPCCall(c.address, "Coordinator.GetInfo", &args, reply)
return c.lastErr
}

// GetCommonConfig returns the current config.
func (c *Client) GetCommonConfig(_ *interface{}, reply *common.Config) error {
var args interface{}
c.lastErr = common.RPCCall(nil, c.address, "Coordinator.GetCommonConfig", &args, reply)
c.lastErr = common.RPCCall(c.address, "Coordinator.GetCommonConfig", &args, reply)
return c.lastErr
}

// GetLayout provides the layout for a shard
func (c *Client) GetLayout(args *GetLayoutArgs, reply *GetLayoutReply) error {
c.lastErr = common.RPCCall(nil, c.address, "Coordinator.GetLayout", args, reply)
c.lastErr = common.RPCCall(c.address, "Coordinator.GetLayout", args, reply)
return c.lastErr
}

// GetIntVec provides the global interest vector
func (c *Client) GetIntVec(args *GetIntVecArgs, reply *GetIntVecReply) error {
c.lastErr = common.RPCCall(nil, c.address, "Coordinator.GetIntVec", args, reply)
c.lastErr = common.RPCCall(c.address, "Coordinator.GetIntVec", args, reply)
return c.lastErr
}

// Commit a set of Writes
func (c *Client) Commit(args *CommitArgs, reply *CommitReply) error {
c.lastErr = common.RPCCall(nil, c.address, "Coordinator.Commit", args, reply)
c.lastErr = common.RPCCall(c.address, "Coordinator.Commit", args, reply)
return c.lastErr
}
87 changes: 0 additions & 87 deletions vendor/github.com/gorilla/rpc/protorpc/protorpc_test.go

This file was deleted.

Loading

0 comments on commit 973d2a5

Please sign in to comment.