diff --git a/src/git.xdrm.io/schastsp/client/client.go b/src/git.xdrm.io/schastsp/client/client.go index 36ed5cc..51593bc 100644 --- a/src/git.xdrm.io/schastsp/client/client.go +++ b/src/git.xdrm.io/schastsp/client/client.go @@ -5,7 +5,7 @@ import ( "fmt" "git.xdrm.io/schastsp/client/keyset" "git.xdrm.io/schastsp/context" - "git.xdrm.io/schastsp/lib/scha" + "git.xdrm.io/schastsp/pkg/scha" "io" ) diff --git a/src/git.xdrm.io/schastsp/client/client.internal.go b/src/git.xdrm.io/schastsp/client/client.internal.go index 57f081c..db6af4f 100644 --- a/src/git.xdrm.io/schastsp/client/client.internal.go +++ b/src/git.xdrm.io/schastsp/client/client.internal.go @@ -4,9 +4,9 @@ import ( "encoding/binary" "fmt" "git.xdrm.io/schastsp/client/keyset" - "git.xdrm.io/schastsp/lib/scha" - "git.xdrm.io/schastsp/lib/timeid" - "git.xdrm.io/schastsp/lib/xor" + "git.xdrm.io/schastsp/pkg/scha" + "git.xdrm.io/schastsp/pkg/timeid" + "git.xdrm.io/schastsp/pkg/xor" ) /* (1) Updates 'key' and 'sync' with files diff --git a/src/git.xdrm.io/schastsp/client/keyset/keyset.go b/src/git.xdrm.io/schastsp/client/keyset/keyset.go index a8373ac..4e2daa0 100644 --- a/src/git.xdrm.io/schastsp/client/keyset/keyset.go +++ b/src/git.xdrm.io/schastsp/client/keyset/keyset.go @@ -4,7 +4,7 @@ import ( "encoding/binary" "errors" "git.xdrm.io/schastsp/context" - "git.xdrm.io/schastsp/lib/scha" + "git.xdrm.io/schastsp/pkg/scha" "io" ) diff --git a/src/git.xdrm.io/schastsp/cmd/client/client.go b/src/git.xdrm.io/schastsp/cmd/client/client.go new file mode 100644 index 0000000..6b06407 --- /dev/null +++ b/src/git.xdrm.io/schastsp/cmd/client/client.go @@ -0,0 +1,116 @@ +package main + +import ( + "time" + "os" + "flag" + "fmt" + "git.xdrm.io/schastsp/context" + "git.xdrm.io/schastsp/client" +) + +/* Store target config paths */ +// var clientConfigPath = "/tmp/cyclichash/client/"; +// var serverConfigPath = "/tmp/cyclichash/server/lastkey"; + + +func main(){ + + executionStart := time.Now().UnixNano() + + /* (1) Flag management (cli arguments) + ---------------------------------------------------------*/ + /* (1) Secret folder */ + clientConfigPath := flag.String("file", "/tmp/schastsp_keys", "Configuration folder, it will contain sensitive data (keys), make sure to control it properly. (default: /tmp/schastsp_keys)") + + /* (2) request | response */ + isRequest := flag.Bool("req", false, "Will generate a request into standard output.") + isResponse := flag.Bool("res", false, "Will proceed a response management from standard input.") + + /* (3) Context window size */ + winSize := flag.Uint("win", 2000, "Time window value in ms. (default: 2000)") + + /* (4) Context minimum depth value */ + minDepth := flag.Uint("min", 0x0f0, "Minimum depth value. (default: 240)") + + /* (5) Context maximum depth value */ + maxDepth := flag.Uint("max", 0xfff, "Maximum depth value. (default: 4095)") + + /* (6) Context depth threshold */ + thrDepth := flag.Uint("thr", 0x00a, "Depth threshold protecting minimum depth to be reached. (default: 10)") + + /* (7) Synchronisation request (special order) */ + syncRequest := flag.Bool("sync", false, "If set, proceeds a synchronisation request and outputs the synchronisation key.") + + /* (8) Parse flags */ + flag.Parse() + + + /* (2) Create context + client + ---------------------------------------------------------*/ + /* (1) Create context */ + ctx, err := context.Create( float64(*winSize) / 1e3, uint16(*minDepth), uint16(*thrDepth), uint16(*maxDepth) ); + if err != nil { os.Stderr.WriteString( fmt.Sprintf("[ERROR:context] %s\n", err) ); return } + + /* (2) Create client */ + cli, err := client.New(ctx, *clientConfigPath) + if err != nil { os.Stderr.WriteString( fmt.Sprintf("[ERROR:client] %s\n", err) ); return } + + + + /* (3) Dispatch execution + ---------------------------------------------------------*/ + /* (1) If synchronisation request */ + if *syncRequest { + synchronisationRequest(cli); + + /* (2) If request */ + } else if *isRequest { + + err = cli.Send(os.Stdin) + if err != nil { os.Stderr.WriteString( fmt.Sprintf("[ERROR:request] %s\n", err) ) } + + /* (3) If response */ + } else if *isResponse { + + err = cli.Receive(os.Stdout) + if err != nil { os.Stderr.WriteString( fmt.Sprintf("[ERROR:response] %s\n", err) ); return } + + /* (4) Else -> nothing */ + }else { + os.Stderr.WriteString( fmt.Sprintf("Missing argument.\n\nYou must give one of the 3 available actions :\n -req to manage a request\n -res to manage a response\n -sync to get a synchronisation key\n") ) + } + + + + + + executionStop := time.Now().UnixNano() + nsElapsed := float64(executionStop - executionStart) + usElapsed := float64(nsElapsed / 1e3) + msElapsed := float64(usElapsed / 1e3) + sElapsed := float64(msElapsed / 1e3) + + if sElapsed >= 1 { fmt.Errorf("executed in %.3f s\n", sElapsed) + } else if msElapsed >= 1 { fmt.Errorf("executed in %.3f ms\n", msElapsed) + } else if usElapsed >= 1 { fmt.Errorf("executed in %.3f us\n", usElapsed) + } else if nsElapsed >= 1 { fmt.Errorf("executed in %.3f ns\n", nsElapsed) } + + return +} + + + + +func synchronisationRequest(cli *client.T){ + + /* (1) Get synchronisation key */ + syncKey, err := cli.SynchronisationKey() + if err != nil { fmt.Errorf("[ERROR:syncKey] %s\n", err); return } + + /* (2) Print synchronisation key */ + os.Stdout.Write(syncKey) + + return; + +} \ No newline at end of file diff --git a/src/git.xdrm.io/schastsp/main.go b/src/git.xdrm.io/schastsp/cmd/simple/simple.go similarity index 100% rename from src/git.xdrm.io/schastsp/main.go rename to src/git.xdrm.io/schastsp/cmd/simple/simple.go diff --git a/src/git.xdrm.io/schastsp/lib/scha/hash.go b/src/git.xdrm.io/schastsp/pkg/scha/hash.go similarity index 98% rename from src/git.xdrm.io/schastsp/lib/scha/hash.go rename to src/git.xdrm.io/schastsp/pkg/scha/hash.go index 1a8cbbc..50ba779 100644 --- a/src/git.xdrm.io/schastsp/lib/scha/hash.go +++ b/src/git.xdrm.io/schastsp/pkg/scha/hash.go @@ -3,7 +3,7 @@ package scha import ( "errors" "crypto/sha512" - "git.xdrm.io/schastsp/lib/xor" + "git.xdrm.io/schastsp/pkg/xor" ) /* (0) Static diff --git a/src/git.xdrm.io/schastsp/lib/scha/hash_test.go b/src/git.xdrm.io/schastsp/pkg/scha/hash_test.go similarity index 100% rename from src/git.xdrm.io/schastsp/lib/scha/hash_test.go rename to src/git.xdrm.io/schastsp/pkg/scha/hash_test.go diff --git a/src/git.xdrm.io/schastsp/lib/timeid/timeid.go b/src/git.xdrm.io/schastsp/pkg/timeid/timeid.go similarity index 100% rename from src/git.xdrm.io/schastsp/lib/timeid/timeid.go rename to src/git.xdrm.io/schastsp/pkg/timeid/timeid.go diff --git a/src/git.xdrm.io/schastsp/lib/timeid/timeid_test.go b/src/git.xdrm.io/schastsp/pkg/timeid/timeid_test.go similarity index 100% rename from src/git.xdrm.io/schastsp/lib/timeid/timeid_test.go rename to src/git.xdrm.io/schastsp/pkg/timeid/timeid_test.go diff --git a/src/git.xdrm.io/schastsp/lib/xor/xor.go b/src/git.xdrm.io/schastsp/pkg/xor/xor.go similarity index 100% rename from src/git.xdrm.io/schastsp/lib/xor/xor.go rename to src/git.xdrm.io/schastsp/pkg/xor/xor.go diff --git a/src/git.xdrm.io/schastsp/server/server.go b/src/git.xdrm.io/schastsp/server/server.go index df6ab5f..7e79c17 100644 --- a/src/git.xdrm.io/schastsp/server/server.go +++ b/src/git.xdrm.io/schastsp/server/server.go @@ -1,7 +1,7 @@ package server import ( - "git.xdrm.io/schastsp/lib/scha" + "git.xdrm.io/schastsp/pkg/scha" "io" "os" "path/filepath" diff --git a/src/git.xdrm.io/schastsp/server/server.internal.go b/src/git.xdrm.io/schastsp/server/server.internal.go index 3242fd0..41bcf94 100644 --- a/src/git.xdrm.io/schastsp/server/server.internal.go +++ b/src/git.xdrm.io/schastsp/server/server.internal.go @@ -4,9 +4,9 @@ import ( "encoding/binary" "errors" "fmt" - "git.xdrm.io/schastsp/lib/scha" - "git.xdrm.io/schastsp/lib/timeid" - "git.xdrm.io/schastsp/lib/xor" + "git.xdrm.io/schastsp/pkg/scha" + "git.xdrm.io/schastsp/pkg/timeid" + "git.xdrm.io/schastsp/pkg/xor" "os" )