V23GoRunner: Add TCP Server code that doesn't work yet.
Also get vanadium blessings working on the app.
Also colors.
Change-Id: Ie90873c4325bce7823b22761e7c0312429c77215
diff --git a/impl/google/services/v23_go_runner/funcs.go b/impl/google/services/v23_go_runner/funcs.go
index 34d5bef..688374e 100644
--- a/impl/google/services/v23_go_runner/funcs.go
+++ b/impl/google/services/v23_go_runner/funcs.go
@@ -7,7 +7,16 @@
package v23_go_runner
import (
+ "fmt"
+
+ "v.io/v23"
"v.io/v23/context"
+ "v.io/v23/rpc"
+ "v.io/v23/security"
+)
+
+const (
+ tcpServerName = "tmp/tcpServerName"
)
// v23GoRunnerFuncs is a map containing go functions keys by unique strings
@@ -15,8 +24,27 @@
// Users must add function entries to this map and rebuild lib/android-lib in
// the vanadium java repository.
var v23GoRunnerFuncs = map[string]func(*context.T) error{
- "bt-rpc": func(ctx *context.T) error {
- ctx.Errorf("bt-rpc test to be implemented")
- return nil
- },
+ "tcp-server": tcpServerFunc,
+ "tcp-client": tcpClientFunc,
+}
+
+func tcpServerFunc(ctx *context.T) error {
+ ctx = v23.WithListenSpec(ctx, rpc.ListenSpec{Proxy: "proxy"})
+ if _, _, err := v23.WithNewServer(ctx, tcpServerName, &echoServer{}, security.AllowEveryone()); err != nil {
+ return err
+ }
+ return nil
+}
+
+func tcpClientFunc(ctx *context.T) error {
+ message := "hi there"
+ var got string
+ if err := v23.GetClient(ctx).Call(ctx, tcpServerName, "Echo", []interface{}{message}, []interface{}{&got}); err != nil {
+ return err
+ }
+ if want := message; got != want {
+ return fmt.Errorf("got %s, want %s", got, want)
+ }
+ ctx.Info("Client successufl executed rpc")
+ return nil
}
diff --git a/impl/google/services/v23_go_runner/util.go b/impl/google/services/v23_go_runner/util.go
new file mode 100644
index 0000000..98191c6
--- /dev/null
+++ b/impl/google/services/v23_go_runner/util.go
@@ -0,0 +1,19 @@
+// Copyright 2015 The Vanadium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build java android
+
+package v23_go_runner
+
+import (
+ "v.io/v23/context"
+ "v.io/v23/rpc"
+)
+
+type echoServer struct{}
+
+func (*echoServer) Echo(ctx *context.T, call rpc.ServerCall, arg string) (string, error) {
+ ctx.Infof("echoServer got message '%s' from %v", arg, call.RemoteEndpoint())
+ return arg, nil
+}