Ejemplo n.º 1
0
func TestSimpleEndpoint(t *testing.T) {
	t.Parallel()
	logs.ResetLogger()

	if testing.Short() {
		t.Skip("this is a long running test.")
	}

	assert := assert.New(t)

	ka, err := cipherset.GenerateKey(0x3a)
	assert.NoError(err)

	kb, err := cipherset.GenerateKey(0x3a)
	assert.NoError(err)

	ea, erra := Open(
		Keys(cipherset.Keys{0x3a: ka}),
		Transport(mux.Config{udp.Config{}, inproc.Config{}}),
		Log(nil))

	eb, errb := Open(
		Keys(cipherset.Keys{0x3a: kb}),
		Transport(mux.Config{udp.Config{}, inproc.Config{}}),
		Log(nil))
	assert.NoError(erra)
	assert.NoError(errb)

	time.Sleep(1 * time.Second)

	identA, err := ea.LocalIdentity()
	assert.NoError(err)

	identB, err := eb.LocalIdentity()
	assert.NoError(err)

	_, err = ea.Dial(identB)
	assert.NoError(err)

	_, err = ea.Dial(identB)
	assert.NoError(err)

	_, err = eb.Dial(identA)
	assert.NoError(err)

	time.Sleep(2*time.Minute + 10*time.Second)

	err = ea.Close()
	assert.NoError(err)

	err = eb.Close()
	assert.NoError(err)
}
Ejemplo n.º 2
0
func main() {
	args, _ := docopt.Parse(usage, nil, true, "0.1-dev", false)

	var (
		output = args["--output"].(string)
		keys   = cipherset.Keys{}
		data   []byte
		err    error
		out    struct {
			Hashname hashname.H            `json:"hashname,omitempty"`
			Parts    cipherset.Parts       `json:"parts,omitempty"`
			Keys     cipherset.PrivateKeys `json:"keys,omitempty"`
		}
	)

	{ // CS 1a
		k, err := cipherset.GenerateKey(0x1a)
		assert(err)
		keys[0x1a] = k
	}

	{ // CS 3a
		k, err := cipherset.GenerateKey(0x3a)
		assert(err)
		keys[0x3a] = k
	}

	out.Keys = cipherset.PrivateKeys(keys)
	out.Parts = hashname.PartsFromKeys(keys)
	out.Hashname, err = hashname.FromIntermediates(out.Parts)
	assert(err)

	if len(out.Keys) == 0 {
		out.Keys = nil
	}
	if len(out.Parts) == 0 {
		out.Keys = nil
	}

	data, err = json.MarshalIndent(out, "", "  ")
	assert(err)

	fmt.Fprintf(os.Stderr, "Generated keys for: %s\n", out.Hashname)

	if output == "-" {
		fmt.Println(string(data))
	} else {
		err := ioutil.WriteFile(output, data, 0600)
		assert(err)
	}
}
Ejemplo n.º 3
0
func join(entry *e3x.Addr) {
	key, err := cipherset.GenerateKey(0x3a)
	if err != nil {
		log.Fatalf("error: %s", err)
	}

	e := e3x.New(cipherset.Keys{0x3a: key}, mux.Config{
		udp.Config{Network: "udp4"},
		udp.Config{Network: "udp6"},
	})

	err = e.Start()
	if err != nil {
		log.Fatalf("error: %s", err)
	}

	defer e.Stop()

	addr, err := e.LocalAddr()
	if err != nil {
		log.Fatalf("error: %s", err)
	}

	ring, err := chord.Join(chord.DefaultConfig(addr.Hashname()), e, entry)
	if err != nil {
		log.Fatalf("error: %s", err)
	}

	defer ring.Shutdown()
	defer ring.Leave()

	select {}
}
Ejemplo n.º 4
0
func main() {
	key, err := cipherset.GenerateKey(0x3a)
	if err != nil {
		log.Fatalf("error: %s", err)
	}

	e := e3x.New(cipherset.Keys{0x3a: key},
		nat.Config{
			mux.Config{
				udp.Config{Network: "udp4"},
				udp.Config{Network: "udp6"},
			},
		})

	err = e.Start()
	if err != nil {
		log.Fatalf("error: %s", err)
	}

	defer e.Stop()

	addr, err := e.LocalAddr()
	if err != nil {
		log.Fatalf("error: %s", err)
	}

	addrJSON, err := addr.MarshalJSON()
	if err != nil {
		log.Fatalf("error: %s", err)
	}

	log.Printf("addr:\n%s", addrJSON)

	ring, err := chord.Create(chord.DefaultConfig(addr.Hashname()), e)
	if err != nil {
		log.Fatalf("error: %s", err)
	}

	defer ring.Shutdown()
	defer ring.Leave()

	go join(addr)
	go join(addr)
	go join(addr)

	select {}
}