Commit 7dcce5ad authored by Loïck Bonniot's avatar Loïck Bonniot

[d] Add configurable addrport and identifier

Fix #3 - Should be merged asap in 192 branch
parent 2b63e8df
Pipeline #642 passed with stage
......@@ -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 {
......
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
......
......@@ -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":
......
......@@ -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":
......
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