zenhotels/astranet

Something wrong with address conversion

ont opened this issue · 4 comments

ont commented

Hello, I am trying to write simple client and server but got strange error with wrong server address name.
Here is code for server:

package main

import (
	"fmt"
	"github.com/zenhotels/astranet"
	"io/ioutil"
	"net"
)

func main() {
	mtx := astranet.New().Server() // create astranet multiplexer

	listener, err := mtx.Bind("", "echo_server")
	if err != nil {
		panic(err)
	}

	mtx.ListenAndServe("tcp4", ":10000")

	for {
		conn, err := listener.Accept()
		if err != nil {
			fmt.Println("Error:", err)
			continue
		}
		go handle(conn)
	}
}

func handle(conn net.Conn) {
	bytes, err := ioutil.ReadAll(conn)
	if err != nil {
		fmt.Println("Error:", err)
		return
	}
	fmt.Println(string(bytes))
}

... and here is code for client:

package main

import (
	"github.com/zenhotels/astranet"
	"github.com/zenhotels/astranet/addr"
)

func main() {
	mtx := astranet.New().Client() // create astranet multiplexer
	mtx.Join("tcp4", "0.0.0.0:10000")

	res, err := addr.Host2Uint("echo_server")
	if err != nil {
		panic(err)
	}
	println("addr conversion -->", res, addr.Uint2Host(res))

	conn, err := mtx.Dial("", "echo_server")
	if err != nil {
		panic(err)
	}

	conn.Write([]byte("test string"))
}

Server starts without errors, but for client I got this output:

addr conversion --> 8775379317412314602 echo_serveo
panic: address echo_serveo: No route to

goroutine 1 [running]:
main.main()
	/home/ont/proj/use/nomnom/tests/src/client/main.go:20 +0x2c5

Pay attention to the error in echo_serveo (wrong last letter o instead of r).
Do I use the name of the service correctly for the mtx.Bind and mtx.Dial?

xlab commented

@ont seems that the length is limited, try to use a shorter one. If you need to add namespaces for the services, use Env()

ont commented

But seems that Bind doesn't have any limitations for service name length:
https://github.com/zenhotels/astranet/blob/master/cli/local2astra/main.go#L110

...
var appName = flag.String("name", uuid.NewV4().String(), "name of application to publish")
...
var fwdService, fwdErr = astraNet.Bind("", *appName)

As I can see this cli program expose local non-astranet service to astranet network as uuid4-named service.
And is it supposed to be accessed via Dial call?

@ont thanks for the issue. Let me check and I will be back.

xlab commented

@biinilya ping, wake up!

#33