1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-27 22:36:12 -04:00
This commit is contained in:
Darien Raymond 2017-10-21 20:40:31 +02:00
parent 948534f480
commit 8c6f73f30b
3 changed files with 26 additions and 17 deletions

View File

@ -1,6 +1,7 @@
package mux
import (
"v2ray.com/core/common/bitmask"
"v2ray.com/core/common/buf"
"v2ray.com/core/common/net"
"v2ray.com/core/common/serial"
@ -15,24 +16,10 @@ const (
SessionStatusKeepAlive SessionStatus = 0x04
)
type Option byte
const (
OptionData Option = 0x01
OptionData bitmask.Byte = 0x01
)
func (o Option) Has(x Option) bool {
return (o & x) == x
}
func (o *Option) Add(x Option) {
*o = (*o | x)
}
func (o *Option) Clear(x Option) {
*o = (*o & (^x))
}
type TargetNetwork byte
const (
@ -64,7 +51,7 @@ n bytes - address
type FrameMetadata struct {
Target net.Destination
SessionID uint16
Option Option
Option bitmask.Byte
SessionStatus SessionStatus
}
@ -120,7 +107,7 @@ func ReadFrameFrom(b []byte) (*FrameMetadata, error) {
f := &FrameMetadata{
SessionID: serial.BytesToUint16(b[:2]),
SessionStatus: SessionStatus(b[2]),
Option: Option(b[3]),
Option: bitmask.Byte(b[3]),
}
b = b[4:]

View File

@ -122,6 +122,7 @@ type Session struct {
transferType protocol.TransferType
}
// Close closes all resources associated with this session.
func (s *Session) Close() {
s.output.Close()
s.input.Close()

21
common/bitmask/byte.go Normal file
View File

@ -0,0 +1,21 @@
package bitmask
// Byte is a bitmask in byte.
type Byte byte
// Has returns true if this bitmask contains another bitmask.
func (b Byte) Has(bb Byte) bool {
return (b & bb) != 0
}
func (b *Byte) Add(bb Byte) {
*b |= bb
}
func (b *Byte) Clear(bb Byte) {
*b &= ^bb
}
func (b *Byte) Toggle(bb Byte) {
*b ^= bb
}