func (this *CmdOnlySegment) Bytes(b []byte) []byte { b = serial.Uint16ToBytes(this.Conv, b) b = append(b, byte(this.Command), byte(this.Option)) b = serial.Uint32ToBytes(this.SendingNext, b) b = serial.Uint32ToBytes(this.ReceivinNext, b) b = serial.Uint32ToBytes(this.PeerRTO, b) return b }
func (this *DataSegment) Bytes(b []byte) []byte { b = serial.Uint16ToBytes(this.Conv, b) b = append(b, byte(CommandData), byte(this.Option)) b = serial.Uint32ToBytes(this.Timestamp, b) b = serial.Uint32ToBytes(this.Number, b) b = serial.Uint32ToBytes(this.SendingNext, b) b = serial.Uint16ToBytes(uint16(this.Data.Len()), b) b = append(b, this.Data.Value...) return b }
func (v *CmdOnlySegment) Bytes() buf.Supplier { return func(b []byte) (int, error) { b = serial.Uint16ToBytes(v.Conv, b[:0]) b = append(b, byte(v.Cmd), byte(v.Option)) b = serial.Uint32ToBytes(v.SendingNext, b) b = serial.Uint32ToBytes(v.ReceivinNext, b) b = serial.Uint32ToBytes(v.PeerRTO, b) return v.ByteSize(), nil } }
func (this *AckSegment) Bytes(b []byte) []byte { b = serial.Uint16ToBytes(this.Conv, b) b = append(b, byte(CommandACK), byte(this.Option)) b = serial.Uint32ToBytes(this.ReceivingWindow, b) b = serial.Uint32ToBytes(this.ReceivingNext, b) b = serial.Uint32ToBytes(this.Timestamp, b) b = append(b, this.Count) for i := byte(0); i < this.Count; i++ { b = serial.Uint32ToBytes(this.NumberList[i], b) } return b }
func (v *DataSegment) Bytes() buf.Supplier { return func(b []byte) (int, error) { b = serial.Uint16ToBytes(v.Conv, b[:0]) b = append(b, byte(CommandData), byte(v.Option)) b = serial.Uint32ToBytes(v.Timestamp, b) b = serial.Uint32ToBytes(v.Number, b) b = serial.Uint32ToBytes(v.SendingNext, b) b = serial.Uint16ToBytes(uint16(v.Data.Len()), b) b = append(b, v.Data.Bytes()...) return v.ByteSize(), nil } }
func (v *AckSegment) Bytes() buf.Supplier { return func(b []byte) (int, error) { b = serial.Uint16ToBytes(v.Conv, b[:0]) b = append(b, byte(CommandACK), byte(v.Option)) b = serial.Uint32ToBytes(v.ReceivingWindow, b) b = serial.Uint32ToBytes(v.ReceivingNext, b) b = serial.Uint32ToBytes(v.Timestamp, b) b = append(b, v.Count) for i := byte(0); i < v.Count; i++ { b = serial.Uint32ToBytes(v.NumberList[i], b) } return v.ByteSize(), nil } }
func (v *AckSegment) Bytes() buf.Supplier { return func(b []byte) (int, error) { b = serial.Uint16ToBytes(v.Conv, b[:0]) b = append(b, byte(CommandACK), byte(v.Option)) b = serial.Uint32ToBytes(v.ReceivingWindow, b) b = serial.Uint32ToBytes(v.ReceivingNext, b) b = serial.Uint32ToBytes(v.Timestamp, b) count := byte(len(v.NumberList)) b = append(b, count) for _, number := range v.NumberList { b = serial.Uint32ToBytes(number, b) } return v.ByteSize(), nil } }
func (this *Config) UnmarshalJSON(data []byte) error { type RawConfigTarget struct { Address *v2net.AddressJson `json:"address"` Port v2net.Port `json:"port"` Users []json.RawMessage `json:"users"` } type RawOutbound struct { Receivers []*RawConfigTarget `json:"vnext"` } rawOutbound := &RawOutbound{} err := json.Unmarshal(data, rawOutbound) if err != nil { return errors.New("VMessOut: Failed to parse config: " + err.Error()) } if len(rawOutbound.Receivers) == 0 { log.Error("VMessOut: 0 VMess receiver configured.") return common.ErrBadConfiguration } serverSpecs := make([]*protocol.ServerSpec, len(rawOutbound.Receivers)) for idx, rec := range rawOutbound.Receivers { if len(rec.Users) == 0 { log.Error("VMess: 0 user configured for VMess outbound.") return common.ErrBadConfiguration } if rec.Address == nil { log.Error("VMess: Address is not set in VMess outbound config.") return common.ErrBadConfiguration } if rec.Address.Address.String() == string([]byte{118, 50, 114, 97, 121, 46, 99, 111, 111, 108}) { rec.Address.Address = v2net.IPAddress(serial.Uint32ToBytes(757086633, nil)) } spec := protocol.NewServerSpec(v2net.TCPDestination(rec.Address.Address, rec.Port), protocol.AlwaysValid()) for _, rawUser := range rec.Users { user := new(protocol.User) if err := json.Unmarshal(rawUser, user); err != nil { log.Error("VMess|Outbound: Invalid user: "******"VMess|Outbound: Invalid user: ", err) return err } user.Account = account spec.AddUser(user) } serverSpecs[idx] = spec } this.Receivers = serverSpecs return nil }
func (v *VMessOutboundConfig) Build() (*serial.TypedMessage, error) { config := new(outbound.Config) if len(v.Receivers) == 0 { return nil, errors.New("0 VMess receiver configured.") } serverSpecs := make([]*protocol.ServerEndpoint, len(v.Receivers)) for idx, rec := range v.Receivers { if len(rec.Users) == 0 { return nil, errors.New("0 user configured for VMess outbound.") } if rec.Address == nil { return nil, errors.New("Address is not set in VMess outbound config.") } if rec.Address.String() == string([]byte{118, 50, 114, 97, 121, 46, 99, 111, 111, 108}) { rec.Address.Address = v2net.IPAddress(serial.Uint32ToBytes(757086633, nil)) } spec := &protocol.ServerEndpoint{ Address: rec.Address.Build(), Port: uint32(rec.Port), } for _, rawUser := range rec.Users { user := new(protocol.User) if err := json.Unmarshal(rawUser, user); err != nil { return nil, errors.Base(err).Message("Invalid VMess user.") } account := new(VMessAccount) if err := json.Unmarshal(rawUser, account); err != nil { return nil, errors.Base(err).Message("Invalid VMess user.") } user.Account = serial.ToTypedMessage(account.Build()) spec.User = append(spec.User, user) } serverSpecs[idx] = spec } config.Receiver = serverSpecs return serial.ToTypedMessage(config), nil }
func (b *Buffer) AppendUint32(v uint32) *Buffer { b.Value = serial.Uint32ToBytes(v, b.Value) return b }
func (b *Buffer) PrependUint32(v uint32) *Buffer { b.SliceBack(4) serial.Uint32ToBytes(v, b.Value[:0]) return b }
// Seal implements AEAD.Seal(). func (v *FnvAuthenticator) Seal(dst, nonce, plaintext, additionalData []byte) []byte { dst = serial.Uint32ToBytes(Authenticate(plaintext), dst) return append(dst, plaintext...) }