Example #1
0
func recvBye(c *conn.Conn, d *connData) (step, error) {
	b, err := c.ReadByte()
	if err != nil {
		return nil, err
	}
	if b != 0 {
		return nil, conn.ErrProto
	}
	return nil, c.CheckSig()
}
Example #2
0
func authClient(c *conn.Conn, d *connData) (step, error) {
	var buf [16]byte
	_, err := io.ReadFull(c, buf[:])
	if err != nil {
		return nil, err
	}
	//clientId := binary.BigEndian.Uint64(buf[:8])
	id := binary.BigEndian.Uint64(buf[8:])
	d.n = getNode(id)
	if d.n == nil {
		return nil, nodeNotFoundError(id)
	}
	c.SetKey(d.n.key)
	c.WriteToHash(buf[:])
	if err = c.CheckSig(); err != nil {
		return nil, err
	}
	log.Info(fmt.Sprintf("client %s: authenticated node %d",
		c.RemoteAddr(), id))
	return recvLogs, c.ReceiveChallenge()
}
Example #3
0
func recvLogs(c *conn.Conn, d *connData) (step, error) {
	var buf [8]byte
	binary.BigEndian.PutUint64(buf[:], d.n.lastSeen)
	_, err := c.Write(buf[:])
	if err != nil {
		return nil, err
	}
	if err = c.SendSig(); err != nil {
		return nil, err
	}
	d.n.lastSeen = uint64(time.Now().UnixNano())
	if err = gob.NewDecoder(c).Decode(&d.r); err != nil {
		return nil, err
	}
	for i := range d.r {
		d.r[i].nodeId = d.n.id
	}
	return sendJobs, c.CheckSig()
}
Example #4
0
func sendJobs(c *conn.Conn, d *connData) (step, error) {
	if err := gob.NewEncoder(c).Encode(d.n.jobs); err != nil {
		return nil, err
	}
	return recvBye, c.SendSig()
}
Example #5
0
func sendGreet(c *conn.Conn, d *connData) (step, error) {
	greets := make([]byte, len(conn.Greet))
	copy(greets, conn.Greet)
	return authClient, c.SendChallenge(greets)
}