diff --git a/dfssc/main.go b/dfssc/main.go index a3e281865d11030d7bcaf7eea8a139776f9bd36d..05d5d93de92e5325e934f492ebae5ba7f307c941 100644 --- a/dfssc/main.go +++ b/dfssc/main.go @@ -5,10 +5,13 @@ import ( "flag" "fmt" "runtime" + + dapi "dfss/dfssd/api" ) var ( verbose bool + demo string fca string // Path to the CA fcert string // Path to the certificate fkey string // Path to the private key @@ -23,6 +26,7 @@ func init() { flag.StringVar(&fcert, "cert", "cert.pem", "Path to the user certificate") flag.StringVar(&fkey, "key", "key.pem", "Path to the private key") flag.StringVar(&addrPort, "host", "localhost:9000", "Host of the DFSS platform") + flag.StringVar(&demo, "d", "", "Demonstrator address and port (empty string disables debug)") flag.IntVar(&localPort, "port", 9005, "Port to use for P2P communication between clients") flag.Usage = func() { @@ -73,6 +77,8 @@ var commands = map[string]command{ func main() { flag.Parse() arg := flag.Arg(0) + dapi.Configure(demo != "", demo, "client") + c, ok := commands[arg] if !ok || flag.NArg()-1 < c.nbArgs { diff --git a/dfssd/api/client.go b/dfssd/api/client.go index be11c07c5dfbdc624724803f22a01118e3f0dfe7..b5480bb2a366918a444523325c1a1d32349a76e7 100644 --- a/dfssd/api/client.go +++ b/dfssd/api/client.go @@ -1,41 +1,40 @@ package api import ( + "time" + "golang.org/x/net/context" "google.golang.org/grpc" "google.golang.org/grpc/grpclog" - "time" ) var ( - // theses are the default parameters - address = "localhost:3000" - identifier = "platform" - demo = false + address, identifier string + demo bool // lazy initializer dial *grpc.ClientConn demoClient DemonstratorClient ) -// Switch for demo mode -// -// Should be used to pass the value of `-d` switch -func Switch(activationSwitch bool) { - demo = activationSwitch - return +// Configure is used to update current parameters. +// Call it at least one time before the first DLog call. +func Configure(activated bool, addrport, id string) { + address = addrport + identifier = id + demo = activated } // Lazy initialisation for demonstrator's connection to server func dInit() error { var err error - dial, err = grpc.Dial(address, grpc.WithInsecure()) + dial, err = grpc.Dial(address, grpc.WithInsecure(), grpc.WithTimeout(10*time.Second)) if err != nil { grpclog.Printf("Fail to dial: %v", err) + return err } demoClient = NewDemonstratorClient(dial) - - return err + return nil } // DClose close the connection with demonstrator server (if any) @@ -45,7 +44,7 @@ func DClose() { if dial != nil { err := dial.Close() if err != nil { - grpclog.Printf("Fail to close dialing: %v", err) + grpclog.Printf("Failed to close dialing with demonstrator: %v", err) } } } @@ -53,9 +52,7 @@ func DClose() { // DLog send a message to the demonstrator // // The client is dialed in a lazy way -// The default demonstrator server address is localhost:3000 func DLog(log string) { - // check demo switch if !demo { return diff --git a/dfssp/main.go b/dfssp/main.go index 7474ecd5ba24bd25ebf4eb2e2c9d843c65316f28..75bfca34362e685809b9d49eb078681a53ab04b7 100644 --- a/dfssp/main.go +++ b/dfssp/main.go @@ -15,16 +15,16 @@ import ( ) var ( - verbose, demo bool - path, country, org, unit, cn, port, address, dbURI string - keySize, rootValidity, certValidity int + verbose bool + path, country, org, unit, cn, port, address, dbURI, demo string + keySize, rootValidity, certValidity int ) func init() { flag.BoolVar(&verbose, "v", false, "Print verbose messages") - flag.BoolVar(&demo, "d", false, "Enable demonstrator") + flag.StringVar(&demo, "d", "", "Demonstrator address and port (empty string disables debug)") flag.StringVar(&port, "p", "9000", "Default port listening") flag.StringVar(&address, "a", "0.0.0.0", "Default address to bind for listening") @@ -67,7 +67,7 @@ func init() { func main() { flag.Parse() command := flag.Arg(0) - dapi.Switch(demo) + dapi.Configure(demo != "", demo, "platform") switch command { case "version": diff --git a/dfsst/main.go b/dfsst/main.go index dbf5198ccc2964af4fd5d9544b03068fe34ba45d..ee3b6a94f62e7b704bd1fcf222da22ffb4fcaca8 100644 --- a/dfsst/main.go +++ b/dfsst/main.go @@ -13,13 +13,14 @@ import ( ) var ( - verbose, demo bool - fca string // Path to the CA - fcert string // Path to the certificate - fkey string // Path to the private key - address string - dbURI string - port string + verbose bool + fca string // Path to the CA + fcert string // Path to the certificate + fkey string // Path to the private key + address string + dbURI string + port string + demo string ) func init() { @@ -28,7 +29,7 @@ func init() { flag.StringVar(&fca, "ca", "ca.pem", "Path to the root certificate") flag.StringVar(&fcert, "cert", "cert.pem", "Path to the user certificate") flag.StringVar(&fkey, "key", "key.pem", "Path to the private key") - flag.BoolVar(&demo, "d", false, "Enable demonstrator") + flag.StringVar(&demo, "d", "", "Demonstrator address and port (empty string disables debug)") flag.StringVar(&port, "p", "9020", "Default port listening") flag.StringVar(&address, "a", "0.0.0.0", "Default address to bind for listening") @@ -58,7 +59,7 @@ func init() { func main() { flag.Parse() command := flag.Arg(0) - dapi.Switch(demo) + dapi.Configure(demo != "", demo, "ttp") switch command { case "version":