Ejemplo n.º 1
0
func NewAdminClient(
	serverName string, serverID *xi.NodeID, serverEnd xt.EndPointI,
	serverCK, serverSK *rsa.PublicKey,
	clusterName string, clusterAttrs uint64,
	size, epCount uint32, e []xt.EndPointI) (
	ac *AdminClient, err error) {

	nodeID, err := xi.New(nil)
	// DEBUG
	fmt.Printf("NewAdminClient: admin ID %x\n", nodeID.Value())
	// END
	if err == nil {
		node, err := xn.NewNew("admin", nodeID, "") // name, id, lfs
		if err == nil {
			cn, err := NewMemberMaker(node,
				xcl.ATTR_ADMIN|xcl.ATTR_SOLO|xcl.ATTR_EPHEMERAL,
				serverName, serverID, serverEnd, serverCK, serverSK,
				clusterName, clusterAttrs, nil, size, epCount, e)

			if err == nil {
				// Start() fills in clusterID
				ac = &AdminClient{
					MemberMaker: *cn,
				}
				// we do NOT invoke node.OpenAcc() on adminClients
				// DEBUG
				fmt.Println("   NewAdminClient: OK exit")
				// END
			}
		}
	}
	return
}
Ejemplo n.º 2
0
func (s *XLSuite) TestMakeHelloMsg(c *C) {
	if VERBOSITY > 0 {
		fmt.Println("TEST_MAKE_HELLO_MSG")
	}
	rng := xr.MakeSimpleRNG()
	id := make([]byte, xu.SHA1_BIN_LEN)
	rng.NextBytes(id)
	nodeID, err := xi.NewNodeID(id)
	c.Assert(err, IsNil)

	name := rng.NextFileName(8)
	lfs := "tmp/" + hex.EncodeToString(id)
	mrX, err := xn.NewNew(name, nodeID, lfs)
	c.Assert(err, IsNil)
	cPubKey := mrX.GetCommsPublicKey()
	c.Assert(cPubKey, Not(IsNil))
	sPubKey := mrX.GetSigPublicKey()
	c.Assert(sPubKey, Not(IsNil))

	// convert MrX's keys to wire form as byte slices
	wcPubKey, err := xc.RSAPubKeyToWire(cPubKey)
	c.Assert(err, IsNil)
	c.Assert(len(wcPubKey) > 0, Equals, true)
	wsPubKey, err := xc.RSAPubKeyToWire(sPubKey)
	c.Assert(err, IsNil)
	c.Assert(len(wsPubKey) > 0, Equals, true)
	c.Assert(wsPubKey, Not(IsNil))

	hello, err := MakeHelloMsg(mrX)
	c.Assert(err, IsNil)
	c.Assert(hello, Not(IsNil))

	// check NodeID
	idInMsg := hello.GetID() // a byte slice, not a NodeID
	c.Assert(id, DeepEquals, idInMsg)

	// these are byte slices
	mcPubKey := hello.GetCommsKey()
	msPubKey := hello.GetSigKey()

	c.Assert(len(mcPubKey), Equals, len(wcPubKey))
	c.Assert(len(msPubKey), Equals, len(wsPubKey)) // FAILS 0, 294

	c.Assert(wcPubKey, DeepEquals, mcPubKey)
	c.Assert(wsPubKey, DeepEquals, msPubKey)
}
Ejemplo n.º 3
0
func (s *XLSuite) makeANode(c *C) (badGuy *xn.Node, acc xt.AcceptorI) {
	rng := xr.MakeSimpleRNG()
	id := make([]byte, xu.SHA1_BIN_LEN)
	rng.NextBytes(id)
	nodeID, err := xi.NewNodeID(id)
	c.Assert(err, IsNil)
	name := rng.NextFileName(8)
	lfs := "tmp/" + hex.EncodeToString(id)
	badGuy, err = xn.NewNew(name, nodeID, lfs)
	c.Assert(err, IsNil)
	accCount := badGuy.SizeAcceptors()
	c.Assert(accCount, Equals, 0)
	ep, err := xt.NewTcpEndPoint("127.0.0.1:0")
	c.Assert(err, IsNil)
	ndx, err := badGuy.AddEndPoint(ep)
	c.Assert(err, IsNil)
	c.Assert(ndx, Equals, 0)
	acc = badGuy.GetAcceptor(0)
	return
}
Ejemplo n.º 4
0
func NewBootstrapper(
	// properties of the prospective cluster member
	name, lfs string, ckPriv, skPriv *rsa.PrivateKey, attrs uint64,
	// reg server properties
	serverName string, serverID *xi.NodeID, serverEnd xt.EndPointI,
	serverCK, serverSK *rsa.PublicKey,
	// cluster attributes
	clusterName string, clusterAttrs uint64, clusterID *xi.NodeID,
	size, epCount uint32, e []xt.EndPointI) (bs *Bootstrapper, err error) {

	// DEBUG
	fmt.Printf("NewBootstrapper: name '%s', lfs '%s'\n", name, lfs)
	// END

	if lfs == "" {
		attrs |= xcl.ATTR_EPHEMERAL
	}
	nodeID, err := xi.New(nil) // ie, make me a NodeID
	if err == nil {
		node, err := xn.NewNew(name, nodeID, lfs)
		if err == nil {
			mn, err := NewMemberMaker(node, attrs,
				serverName, serverID, serverEnd, serverCK, serverSK,
				clusterName, clusterAttrs, clusterID, size, epCount, e)

			if err == nil {
				bs = &Bootstrapper{
					DoneCh:      make(chan error),
					MemberMaker: *mn,
				}
			}
		}
	}
	return

}
Ejemplo n.º 5
0
func (s *XLSuite) TestPortlandRegCred(c *C) {
	if VERBOSITY > 0 {
		fmt.Println("\nTEST_PORTLAND_REG_CRED")
	}
	rng := xr.MakeSimpleRNG()
	_ = rng

	// read our local copy of the reg cred
	rcData, err := ioutil.ReadFile("portlandRegCred.dat")
	c.Assert(err, IsNil)
	rc, err := ParseRegCred(string(rcData))
	c.Assert(err, IsNil)
	c.Assert(rc, NotNil)

	// DEBUG
	fmt.Println("portlandRegCred_test PORTLAND - A PUZZLE")
	// END

	// set up the client --------------------------------------------
	name := rng.NextFileName(8)
	lfs := path.Join("tmp", name)
	found, err := xf.PathExists(lfs)
	c.Assert(err, IsNil)
	for found {
		name = rng.NextFileName(8)
		lfs = path.Join("tmp", name)
		found, err = xf.PathExists(lfs)
		c.Assert(err, IsNil)
	}

	ep, err := xt.NewTcpEndPoint("127.0.0.1:0")
	c.Assert(err, IsNil)
	e := []xt.EndPointI{ep}
	c.Assert(e, NotNil)

	nodeID, err := xi.New(nil)
	c.Assert(err, IsNil)

	node, err := xn.NewNew(name, nodeID, lfs)
	c.Assert(err, IsNil)

	// DEBUG
	fmt.Printf("Portland client is at %v; lfs is %s\n",
		e, lfs)
	// END

	// set up its relationship to the server ------------------------
	serverName := rc.Name
	serverID := rc.ID
	serverEnd := rc.EndPoints
	c.Assert(serverEnd, NotNil)
	c.Assert(len(serverEnd) > 0, Equals, true)
	c.Assert(serverEnd[0], NotNil)
	// XXX TOO RIGID
	c.Assert(serverEnd[0].String(), Equals, "TcpEndPoint: 54.186.197.123:56789")
	// END
	serverCK := rc.CommsPubKey
	serverSK := rc.SigPubKey

	sc, err := NewSoloMember(node, serverName, serverID, serverEnd[0],
		serverCK, serverSK, e)
	c.Assert(err, IsNil)
	c.Assert(sc, NotNil)

	// DEBUG
	fmt.Println("SoloMember CREATED")

	// END

	// 3. run the client
	sc.Start()
	err = <-sc.DoneCh

	// 4.  verify that the client LFS exists and is correct ---------
	found, err = xf.PathExists(lfs)
	c.Assert(err, IsNil)
	c.Assert(found, Equals, true)

	// 5.  shut down the client -------------------------------------
	sc.CloseAcc() // should close any acceptors

}
Ejemplo n.º 6
0
func (s *XLSuite) TestSoloMember(c *C) {
	if VERBOSITY > 0 {
		fmt.Println("\nTEST_SOLO_CLIENT")
	}

	rng := xr.MakeSimpleRNG()

	// 1.  create a new ephemeral server ----------------------------
	es, err := NewEphServer()
	c.Assert(err, IsNil)
	c.Assert(es, NotNil)

	server := es.Server

	c.Assert(&server.RegNode.ckPriv.PublicKey,
		DeepEquals, server.GetCommsPublicKey())
	serverName := server.GetName()
	serverID := server.GetNodeID()
	serverEnd := server.GetEndPoint(0)
	serverCK := server.GetCommsPublicKey()
	serverSK := server.GetSigPublicKey()
	c.Assert(serverEnd, NotNil)

	// start the mock server ------------------------------
	err = es.Start()
	c.Assert(err, IsNil)

	// 2. create the solo client ------------------------------------
	name := rng.NextFileName(8)
	lfs := path.Join("tmp", name)
	found, err := xf.PathExists(lfs)
	c.Assert(err, IsNil)
	for found {
		name = rng.NextFileName(8)
		lfs = path.Join("tmp", name)
		found, err = xf.PathExists(lfs)
		c.Assert(err, IsNil)
	}

	ep, err := xt.NewTcpEndPoint("127.0.0.1:0")
	c.Assert(err, IsNil)
	e := []xt.EndPointI{ep}

	nodeID, err := xi.New(nil)
	c.Assert(err, IsNil)

	node, err := xn.NewNew(name, nodeID, lfs)
	c.Assert(err, IsNil)

	sc, err := NewSoloMember(node, serverName, serverID, serverEnd,
		serverCK, serverSK, e)
	c.Assert(err, IsNil)
	c.Assert(sc, NotNil)

	// 3. run the client
	sc.Start()
	err = <-sc.DoneCh

	// 4.  verify that the client LFS exists and is correct ---------
	found, err = xf.PathExists(lfs)
	c.Assert(err, IsNil)
	c.Assert(found, Equals, true)

	// 5.  shut down the client -------------------------------------
	sc.CloseAcc() // should close any acceptors

	// 6.  stop the server, closing its acceptor --------------------
	es.Stop()

}