func (this *Node) newPacket(command Command, responseTo []byte, data isPacket_Data) Packet {
	return NewPacket(this.dht, command, responseTo, data)
}
func NewPacket(dht *Dht, command Command, responseTo Hash, data interface{}) Packet {
addr, err := net.ResolveUDPAddr("udp", dht.options.ListenAddr)
packet := Packet{
Header: &PacketHeader{
DateSent:    time.Now().UnixNano(),
Command:     command,
ResponseTo:  responseTo,
MessageHash: []byte{},
Sender: &PacketContact{
Addr: addr.String(),
Hash: dht.hash,
},
},
}
packet.SetData(data)
tmp, err := msgpack.Marshal(&packet)
if err != nil {
dht.logger.Warning(err)
}
packet.Header.MessageHash = NewHash(tmp)
return packet
}
package dht
import (
	"encoding/hex"
	"errors"
	"net"
	"time"
	"github.com/golang/protobuf/proto"
	"github.com/vmihailenco/msgpack"
)
type Callback func(val Packet, err error)
type CallbackChan struct {
	timer *time.Timer
	c     chan interface{}
}
type Node struct {
	contact  PacketContact
	lastSeen int64
	addr     net.Addr
	dht      *Dht
}
type StoreInst struct {
	Hash Hash
	Data []byte
}
var nonce int64 = 0
func NewPacket(dht *Dht, command Command, responseTo Hash, data isPacket_Data) Packet {
	addr, err := net.ResolveUDPAddr("udp", dht.options.ListenAddr)
	packet := Packet{
		Header: &PacketHeader{
			Nonce:       nonce,
			DateSent:    time.Now().UnixNano(),
			Command:     command,
			ResponseTo:  responseTo,
			MessageHash: []byte{},
			Sender: &PacketContact{
				Addr: addr.String(),
				Hash: dht.hash,
			},
		},
		Data: data,
	}
	nonce++
	tmp, err := msgpack.Marshal(&packet.Header)
	if err != nil {
		dht.logger.Warning(err)
	}
	packet.Header.MessageHash = NewHash(tmp)
	return packet
}