Exemple #1
0
func (c *Connection) Serve() {
	for {
		r := c.conn.Next()
		c.conn.StartRequest(r)
		s, e := c.conn.ReadLine()
		if e != nil {
			break
		}
		pbmatch := pullblock.FindStringSubmatch(s)
		switch {
		case s == "PUSHBLOCK":
			_, e = io.ReadFull(c.conn.R, c.block1)
			if e == nil {
				bucket.StoreBlock(c.bck, c.block1)
			}
			c.conn.EndRequest(r)
			go c.donothing(r)
		case pbmatch != nil:
			key, e := base64.URLEncoding.DecodeString(pbmatch[1])
			c.conn.EndRequest(r)
			if e != nil {
				go c.sendLine(r, 901, "base64 error")
			} else {
				go c.sendBlock(r, key)
			}
		default:
			c.conn.EndRequest(r)
			go c.sendLine(r, 909, "command error")
		}
	}
	// println("close Connection")
	c.conn.Close()
}
Exemple #2
0
// block1 should be already initialized
func GenerateTupleFromBlock(block1, block2 []byte, rand io.Reader, bck bucket.Bucket, tupleSize int) (tuple [][]byte, e error) {
	tuple = make([][]byte, tupleSize)
	for i := 1; i < tupleSize; i++ {
		e = blockutil.RandomBlock(rand, block2)
		if e != nil {
			return
		}
		tuple[i], e = bucket.StoreBlock(bck, block2)
		if e != nil {
			return
		}
		blockutil.XorBlock(block1, block2) // block1 ^= block2
	}
	tuple[0], e = bucket.StoreBlock(bck, block1)
	if e != nil {
		return
	}
	return
}