func initialize() { kilog.Info("SAGIRI version %v initializing...", VERSION) flag.Parse() lol, err := getPublicIP() kilog.Info("%v %v", lol, err) if isDirectory { runDir() os.Exit(0) } switch dirHelper { case "internal": dirProvider = directory.DefaultProvider("sanctum.sagiri.niwl.io:2378") } // obtain directory info id := directory.NewClient(natrium.EdDSAGenerateKey()) kilog.Debug("master key: %v", id.GetPrivate().PublicKey()) getNeighs(id) go func() { for { time.Sleep(time.Minute) getNeighs(id) } }() // set up core node if onionPort != 0 { ip, err := getPublicIP() if err != nil { panic(err.Error()) } id.SetAddress(&net.TCPAddr{IP: ip, Port: onionPort, Zone: "tcp"}) dirClient = id go runCore(id) } else { dirClient = id startSocks() startControl() go func() { log.Println(http.ListenAndServe("0.0.0.0:6060", nil)) }() } kilog.Info("SAGIRI finished initializing.") }
func TestDirectoryCoreEdge(t *testing.T) { spinTestDir() defer stopTestDir() for i := 0; i < 10; i++ { //time.Sleep(time.Second) clnt := directory.NewClient(natrium.EdDSAGenerateKey()) prv := directory.DefaultProvider("127.0.0.1:12345") addr, _ := net.ResolveTCPAddr("tcp", "127.0.0.1:0") __lol, err := net.ListenTCP("tcp", addr) if err != nil { panic(err.Error()) } clnt.SetAddress(__lol.Addr().(*net.TCPAddr)) addr = __lol.Addr().(*net.TCPAddr) __lol.Close() lol, err := kiricom.EasyListen(addr.String(), nil, clnt.GetSecret()) if err != nil { panic(err.Error()) } defer lol.Close() state := NewNodeState(prv, clnt) go func() { for { clnt, err := lol.Accept() if err != nil { return } go func() { defer clnt.Close() err := state.HandleClient(clnt) if err != nil { kilog.Debug(err.Error()) } }() } }() err = prv.JoinCore(clnt) if err != nil { log.Fatal(err.Error()) } } time.Sleep(time.Second * 2) clnt := directory.NewClient(natrium.EdDSAGenerateKey()) prv := directory.DefaultProvider("127.0.0.1:12345") neiz, err := prv.JoinEdge(clnt) if err != nil { panic(err.Error()) } fmt.Println(neiz) // route in a circle func() { spider, err := NewClient(neiz[0]) if err != nil { panic(err.Error()) } defer spider.Destroy() for i := 0; i < 11; i++ { fmt.Println(spider.curpk) lawl, err := spider.ListNeighs() if err != nil { panic(err.Error()) } err = spider.ConnectNext(lawl[0]) if err != nil { panic(err.Error()) } //time.Sleep(time.Second) } }() fmt.Println("--- ROUTING DONE ---") // time to test ambassadors! func() { alpha, err := NewClient(neiz[0]) if err != nil { panic(err.Error()) } beta, err := NewClient(neiz[0]) if err != nil { panic(err.Error()) } defer alpha.Destroy() defer beta.Destroy() // alpha registers, beta connects id := natrium.EdDSAGenerateKey() srv, err := alpha.RegAmbassador(id.PublicKey()) if err != nil { panic(err.Error()) } clnt, err := beta.ConnAmbassador(id.PublicKey()) if err != nil { panic(err.Error()) } // throwaway echo server go func() { lol, err := srv.Accept() if err != nil { panic(err.Error()) } defer lol.Close() io.Copy(lol, lol) }() // test with random stuff xaxa := make([]byte, 16) rand.Read(xaxa) sok, err := clnt.Dial() if err != nil { panic(err.Error()) } sok.Write(xaxa) resp := make([]byte, 16) io.ReadFull(sok, resp) fmt.Printf("%x\n", xaxa) fmt.Printf("%x\n", resp) if subtle.ConstantTimeCompare(resp, xaxa) != 1 { t.Fatal("ambassador broken") } }() fmt.Println("--- AMBASSADOR DONE ---") }