1 files changed, 32 insertions(+), 7 deletions(-)

M cmd/kgp_client/main.go
M cmd/kgp_client/main.go +32 -7
@@ 9,6 9,8 @@ import (
 	"net"
 	"os"
 	"strings"
+
+	"bitbucket.org/henry/kgp"
 )
 
 type Address struct {

          
@@ 17,14 19,23 @@ type Address struct {
 
 func ParseAddress(s string) (a Address, err error) {
 	addrParts := strings.SplitN(s, "://", 2)
-	if len(addrParts) == 1 && addrParts[0] != "" {
+	// Validate input
+	switch len(addrParts) {
+	case 1:
+		// assume it's a tcp address if no protocol was specified
 		addrParts = []string{"tcp", addrParts[0]}
+	case 2:
+		// ok
+	default:
+		err = fmt.Errorf("invalid address %s", s)
+		return
 	}
-	// Validate input
+
 	switch addrParts[0] {
 	case "unix":
-		// No validation needed, it's a filename
+		// No validation, it's a filename we'll just try to open it when the time comes
 	case "tcp":
+		// make sure we have a valid host:port value
 		_, _, err = net.SplitHostPort(addrParts[1])
 		if err != nil {
 			return

          
@@ 39,6 50,12 @@ func ParseAddress(s string) (a Address, 
 	return
 }
 
+func handshake(conn net.Conn) error {
+	var a, err = kgp.ReadAnnouncement(conn)
+	log.Print(a)
+	return err
+}
+
 const usage = `usage: kgp_client upstream downstream
 
   Example: upstream KGP server is tunnel.example.com:443 and the downstream

          
@@ 77,13 94,21 @@ func main() {
 			log.Fatalln(err)
 		}
 	}
-	var m, _ = ioutil.ReadAll(meta)
-	fmt.Println(upstream, downstream, m)
+	log.Print("upstream", upstream, "downstream", downstream)
 
 	upconn, err := net.Dial(upstream.Network, upstream.Address)
 	if err != nil {
 		log.Fatalln("error connecting to ", upstream, ": ", err.Error())
 	}
-	msg, err := ioutil.ReadAll(upconn)
-	fmt.Println(msg)
+
+	if err = handshake(upconn); err != nil {
+		log.Fatalln(err)
+	}
+	var my = kgp.Announcement{
+		Metadata: meta,
+	}
+	if _, err := my.Write(upconn); err != nil {
+		log.Fatalln(err)
+	}
+	ioutil.ReadAll(upconn)
 }