2015-09-22 08:45:03 -04:00
|
|
|
package net
|
|
|
|
|
2015-10-08 08:46:18 -04:00
|
|
|
import (
|
|
|
|
"github.com/v2ray/v2ray-core/common/alloc"
|
|
|
|
)
|
|
|
|
|
2015-09-22 08:45:03 -04:00
|
|
|
type Packet interface {
|
|
|
|
Destination() Destination
|
2015-10-08 08:46:18 -04:00
|
|
|
Chunk() *alloc.Buffer // First chunk of this commnunication
|
2015-09-22 08:45:03 -04:00
|
|
|
MoreChunks() bool
|
|
|
|
}
|
|
|
|
|
2015-10-08 08:46:18 -04:00
|
|
|
func NewPacket(dest Destination, firstChunk *alloc.Buffer, moreChunks bool) Packet {
|
2015-10-02 09:32:26 -04:00
|
|
|
return &packetImpl{
|
|
|
|
dest: dest,
|
|
|
|
data: firstChunk,
|
|
|
|
moreData: moreChunks,
|
2015-09-22 08:45:03 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-02 09:32:26 -04:00
|
|
|
type packetImpl struct {
|
|
|
|
dest Destination
|
2015-10-08 08:46:18 -04:00
|
|
|
data *alloc.Buffer
|
2015-10-02 09:32:26 -04:00
|
|
|
moreData bool
|
2015-09-28 08:57:43 -04:00
|
|
|
}
|
|
|
|
|
2015-10-02 09:32:26 -04:00
|
|
|
func (packet *packetImpl) Destination() Destination {
|
|
|
|
return packet.dest
|
2015-09-22 08:45:03 -04:00
|
|
|
}
|
|
|
|
|
2015-10-08 08:46:18 -04:00
|
|
|
func (packet *packetImpl) Chunk() *alloc.Buffer {
|
2015-09-22 08:45:03 -04:00
|
|
|
return packet.data
|
|
|
|
}
|
|
|
|
|
2015-10-02 09:32:26 -04:00
|
|
|
func (packet *packetImpl) MoreChunks() bool {
|
|
|
|
return packet.moreData
|
2015-09-22 08:45:03 -04:00
|
|
|
}
|