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() }
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() }
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() }
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() }
func sendGreet(c *conn.Conn, d *connData) (step, error) { greets := make([]byte, len(conn.Greet)) copy(greets, conn.Greet) return authClient, c.SendChallenge(greets) }