mirror of https://github.com/v2ray/v2ray-core
				
				
				
			bitmask
							parent
							
								
									948534f480
								
							
						
					
					
						commit
						8c6f73f30b
					
				| 
						 | 
					@ -1,6 +1,7 @@
 | 
				
			||||||
package mux
 | 
					package mux
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
 | 
						"v2ray.com/core/common/bitmask"
 | 
				
			||||||
	"v2ray.com/core/common/buf"
 | 
						"v2ray.com/core/common/buf"
 | 
				
			||||||
	"v2ray.com/core/common/net"
 | 
						"v2ray.com/core/common/net"
 | 
				
			||||||
	"v2ray.com/core/common/serial"
 | 
						"v2ray.com/core/common/serial"
 | 
				
			||||||
| 
						 | 
					@ -15,24 +16,10 @@ const (
 | 
				
			||||||
	SessionStatusKeepAlive SessionStatus = 0x04
 | 
						SessionStatusKeepAlive SessionStatus = 0x04
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type Option byte
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
const (
 | 
					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
 | 
					type TargetNetwork byte
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const (
 | 
					const (
 | 
				
			||||||
| 
						 | 
					@ -64,7 +51,7 @@ n bytes - address
 | 
				
			||||||
type FrameMetadata struct {
 | 
					type FrameMetadata struct {
 | 
				
			||||||
	Target        net.Destination
 | 
						Target        net.Destination
 | 
				
			||||||
	SessionID     uint16
 | 
						SessionID     uint16
 | 
				
			||||||
	Option        Option
 | 
						Option        bitmask.Byte
 | 
				
			||||||
	SessionStatus SessionStatus
 | 
						SessionStatus SessionStatus
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -120,7 +107,7 @@ func ReadFrameFrom(b []byte) (*FrameMetadata, error) {
 | 
				
			||||||
	f := &FrameMetadata{
 | 
						f := &FrameMetadata{
 | 
				
			||||||
		SessionID:     serial.BytesToUint16(b[:2]),
 | 
							SessionID:     serial.BytesToUint16(b[:2]),
 | 
				
			||||||
		SessionStatus: SessionStatus(b[2]),
 | 
							SessionStatus: SessionStatus(b[2]),
 | 
				
			||||||
		Option:        Option(b[3]),
 | 
							Option:        bitmask.Byte(b[3]),
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	b = b[4:]
 | 
						b = b[4:]
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -122,6 +122,7 @@ type Session struct {
 | 
				
			||||||
	transferType protocol.TransferType
 | 
						transferType protocol.TransferType
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Close closes all resources associated with this session.
 | 
				
			||||||
func (s *Session) Close() {
 | 
					func (s *Session) Close() {
 | 
				
			||||||
	s.output.Close()
 | 
						s.output.Close()
 | 
				
			||||||
	s.input.Close()
 | 
						s.input.Close()
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -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
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
		Reference in New Issue