Beispiel #1
0
func (s *XLSuite) makeEntryData(c *C, rng *xr.PRNG, whichSHA int) (
	t int64, key, nodeID []byte, src, path string) {

	t = rng.Int63() // timestamp
	var length int
	switch whichSHA {
	case xu.USING_SHA1:
		length = xu.SHA1_BIN_LEN
	case xu.USING_SHA2:
		length = xu.SHA2_BIN_LEN
	case xu.USING_SHA3:
		length = xu.SHA3_BIN_LEN
		// XXX DEFAULT = ERROR
	}
	key = make([]byte, length)
	rng.NextBytes(key)

	nodeID = make([]byte, length)
	rng.NextBytes(nodeID)

	src = rng.NextFileName(32) // 32 is max len
	path = rng.NextFileName(32)
	for strings.Contains(path, ".") { // that crude fix
		path = rng.NextFileName(32)
	}
	return
}
Beispiel #2
0
// Make a RegCluster for test purposes.  Cluster member names are guaranteed
// to be unique but the name of the cluster itself may not be.
//
// THIS IS THE REGISTRY'S VIEW OF A CLUSTER
func (s *XLSuite) makeARegCluster(c *C, rng *xr.PRNG, epCount, size uint32) (
	rc *RegCluster) {

	var err error
	c.Assert(MIN_CLUSTER_SIZE <= size && size <= MAX_CLUSTER_SIZE, Equals, true)

	attrs := uint64(rng.Int63())
	name := rng.NextFileName(8) // no guarantee of uniqueness
	id := s.makeANodeID(c, rng)

	rc, err = NewRegCluster(name, id, attrs, size, epCount)
	c.Assert(err, IsNil)

	for count := uint32(0); count < size; count++ {
		cm := s.makeAClientInfo(c, rng, epCount)
		for {
			if _, ok := rc.MembersByName[cm.GetName()]; ok {
				// name is in use, so try again
				cm = s.makeAClientInfo(c, rng, epCount)
			} else {
				err = rc.AddMember(cm)
				c.Assert(err, IsNil)
				break
			}
		}
	}
	return
}
Beispiel #3
0
func (s *XLSuite) makeAMemberInfo(c *C, rng *xr.PRNG) *xcl.MemberInfo {
	attrs := uint64(rng.Int63())
	peer, err := xn.NewPeer(
		rng.NextFileName(8),
		s.makeANodeID(c, rng),
		&s.makeAnRSAKey(c).PublicKey,
		&s.makeAnRSAKey(c).PublicKey,
		nil, // overlays
		nil) // XXX CONNECTORS
	c.Assert(err, IsNil)
	return &xcl.MemberInfo{
		Attrs: attrs,
		Peer:  peer,
	}
} // GEEP
Beispiel #4
0
func (s *XLSuite) makeAMemberInfo(c *C, rng *xr.PRNG) *xcl.MemberInfo {
	attrs := uint64(rng.Int63())
	bn, err := xn.NewBaseNode(
		rng.NextFileName(8),
		s.makeANodeID(c, rng),
		&s.makeAnRSAKey(c).PublicKey,
		&s.makeAnRSAKey(c).PublicKey,
		nil) // overlays
	c.Assert(err, IsNil)

	asPeer := &xn.Peer{
		BaseNode: *bn,
	}
	return &xcl.MemberInfo{
		Attrs: attrs,
		Peer:  asPeer,
	}
}
Beispiel #5
0
func (s *XLSuite) makeAClientInfo(c *C, rng *xr.PRNG, epCount uint32) *ClientInfo {
	attrs := uint64(rng.Int63())
	var myEnds []string
	for i := uint32(0); i < epCount; i++ {
		myEnds = append(myEnds, "127.0.0.1:0")
	}
	bn, err := xn.NewBaseNode(
		rng.NextFileName(8),
		s.makeANodeID(c, rng),
		&s.makeAnRSAKey(c).PublicKey,
		&s.makeAnRSAKey(c).PublicKey,
		nil) // overlays
	c.Assert(err, IsNil)
	return &ClientInfo{
		Attrs:    attrs,
		MyEnds:   myEnds,
		BaseNode: *bn,
	}
}
Beispiel #6
0
func (s *XLSuite) makeACluster(c *C, rng *xr.PRNG, epCount, size uint32) (
	rc *reg.RegCluster) {

	var err error
	c.Assert(1 < size && size <= 64, Equals, true)

	attrs := uint64(rng.Int63())
	name := rng.NextFileName(8) // no guarantee of uniqueness
	id := s.makeANodeID(c, rng)

	rc, err = reg.NewRegCluster(name, id, attrs, size, epCount)
	c.Assert(err, IsNil)

	for count := uint32(0); count < size; count++ {
		cm := s.makeAMemberInfo(c, rng)
		for {
			if _, ok := rc.MembersByName[cm.Peer.GetName()]; ok {
				// name is in use, so try again
				cm = s.makeAMemberInfo(c, rng)
			} else {
				// copy the connector list as strings
				myEnds := make([]string, 0, 0)
				for endCount := 0; endCount < int(size); endCount++ {
					thisEnd := cm.Peer.GetConnector(endCount).String()
					myEnds = append(myEnds, thisEnd)
				}
				asClient := &reg.ClientInfo{
					Attrs:    cm.Attrs,
					MyEnds:   myEnds,
					BaseNode: cm.Peer.BaseNode,
				}
				err = rc.AddMember(asClient)
				break
			}
		}
	}
	return
}
Beispiel #7
0
func (s *XLSuite) doTestRegexes(c *C, rng *xr.PRNG, whichSHA int) {
	t := rng.Int63()
	var length int
	switch whichSHA {
	case xu.USING_SHA1:
		length = xu.SHA1_BIN_LEN
	case xu.USING_SHA2:
		length = xu.SHA2_BIN_LEN
	case xu.USING_SHA3:
		length = xu.SHA3_BIN_LEN
		// XXX DEFAULT = ERROR
	}
	key := make([]byte, length)
	rng.NextBytes(key)
	hexKey := hex.EncodeToString(key)

	nodeID := make([]byte, length)
	rng.NextBytes(nodeID)
	hexNodeID := hex.EncodeToString(nodeID)

	src := rng.NextFileName(32) // 32 is max len
	path := rng.NextFileName(32)
	for strings.Contains(path, ".") { // XXX a crude fix
		path = rng.NextFileName(32)
	}

	expected := fmt.Sprintf("%d %s %s \"%s\" %s",
		t, hexKey, hexNodeID, src, path)

	switch whichSHA {
	case xu.USING_SHA1:
		c.Assert(bodyLine1RE.MatchString(expected), Equals, true)
		groups := bodyLine1RE.FindStringSubmatch(expected)
		c.Assert(groups, Not(IsNil))
		c.Assert(len(groups), Equals, 6) // 5 fields + match on all

		c.Assert(bodyLine3RE.MatchString(expected), Equals, false)

	case xu.USING_SHA2:
		c.Assert(bodyLine2RE.MatchString(expected), Equals, true)
		groups := bodyLine2RE.FindStringSubmatch(expected)
		c.Assert(groups, Not(IsNil))
		c.Assert(len(groups), Equals, 6) // 5 fields + match on all

		c.Assert(bodyLine1RE.MatchString(expected), Equals, false)

	case xu.USING_SHA3:
		// DEBUG
		if !bodyLine3RE.MatchString(expected) {
			fmt.Printf("DOESN'T MATCH PATTERN: %s\n", expected)
		}
		// END
		c.Assert(bodyLine3RE.MatchString(expected), Equals, true)
		groups := bodyLine3RE.FindStringSubmatch(expected)
		c.Assert(groups, Not(IsNil))
		c.Assert(len(groups), Equals, 6)

		c.Assert(bodyLine1RE.MatchString(expected), Equals, false)
		// XXX DEFAULT = ERROR
	}
}