mirror of
https://github.com/PretendoNetwork/nex-go.git
synced 2025-04-02 11:02:14 -04:00
Compare commits
No commits in common. "master" and "v2.1.2" have entirely different histories.
4 changed files with 22 additions and 62 deletions
|
@ -4,7 +4,6 @@ import (
|
||||||
"crypto/hmac"
|
"crypto/hmac"
|
||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
|
||||||
|
@ -178,10 +177,6 @@ func (p *PRUDPPacketLite) decode() error {
|
||||||
return fmt.Errorf("Failed to decode PRUDPLite options. %s", err.Error())
|
return fmt.Errorf("Failed to decode PRUDPLite options. %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
if p.readStream.Remaining() < uint64(payloadLength) {
|
|
||||||
return errors.New("Failed to read PRUDPLite payload. Not have enough data")
|
|
||||||
}
|
|
||||||
|
|
||||||
p.payload = p.readStream.ReadBytesNext(int64(payloadLength))
|
p.payload = p.readStream.ReadBytesNext(int64(payloadLength))
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -213,10 +208,6 @@ func (p *PRUDPPacketLite) Bytes() []byte {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PRUDPPacketLite) decodeOptions() error {
|
func (p *PRUDPPacketLite) decodeOptions() error {
|
||||||
if p.readStream.Remaining() < uint64(p.optionsLength) {
|
|
||||||
return errors.New("Not have enough data")
|
|
||||||
}
|
|
||||||
|
|
||||||
data := p.readStream.ReadBytesNext(int64(p.optionsLength))
|
data := p.readStream.ReadBytesNext(int64(p.optionsLength))
|
||||||
optionsStream := NewByteStreamIn(data, p.server.LibraryVersions, p.server.ByteStreamSettings)
|
optionsStream := NewByteStreamIn(data, p.server.LibraryVersions, p.server.ByteStreamSettings)
|
||||||
|
|
||||||
|
@ -240,11 +231,7 @@ func (p *PRUDPPacketLite) decodeOptions() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if optionID == 1 {
|
if optionID == 1 {
|
||||||
if optionsStream.Remaining() < uint64(optionSize) {
|
p.connectionSignature = optionsStream.ReadBytesNext(int64(optionSize))
|
||||||
err = errors.New("Failed to read connection signature. Not have enough data")
|
|
||||||
} else {
|
|
||||||
p.connectionSignature = optionsStream.ReadBytesNext(int64(optionSize))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if optionID == 4 {
|
if optionID == 4 {
|
||||||
|
@ -266,11 +253,7 @@ func (p *PRUDPPacketLite) decodeOptions() error {
|
||||||
|
|
||||||
if p.packetType == constants.ConnectPacket && !p.HasFlag(constants.PacketFlagAck) {
|
if p.packetType == constants.ConnectPacket && !p.HasFlag(constants.PacketFlagAck) {
|
||||||
if optionID == 0x80 {
|
if optionID == 0x80 {
|
||||||
if optionsStream.Remaining() < uint64(optionSize) {
|
p.liteSignature = optionsStream.ReadBytesNext(int64(optionSize))
|
||||||
err = errors.New("Failed to read lite signature. Not have enough data")
|
|
||||||
} else {
|
|
||||||
p.liteSignature = optionsStream.ReadBytesNext(int64(optionSize))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -89,10 +89,6 @@ func (p *PRUDPPacketV1) decode() error {
|
||||||
return fmt.Errorf("Failed to decode PRUDPv1 header. %s", err.Error())
|
return fmt.Errorf("Failed to decode PRUDPv1 header. %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
if p.readStream.Remaining() < 16 {
|
|
||||||
return errors.New("Failed to read PRUDPv1 signature. Not have enough data")
|
|
||||||
}
|
|
||||||
|
|
||||||
p.signature = p.readStream.ReadBytesNext(16)
|
p.signature = p.readStream.ReadBytesNext(16)
|
||||||
|
|
||||||
err = p.decodeOptions()
|
err = p.decodeOptions()
|
||||||
|
@ -100,10 +96,6 @@ func (p *PRUDPPacketV1) decode() error {
|
||||||
return fmt.Errorf("Failed to decode PRUDPv1 options. %s", err.Error())
|
return fmt.Errorf("Failed to decode PRUDPv1 options. %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
if p.readStream.Remaining() < uint64(p.payloadLength) {
|
|
||||||
return errors.New("Failed to read PRUDPv1 payload. Not have enough data")
|
|
||||||
}
|
|
||||||
|
|
||||||
p.payload = p.readStream.ReadBytesNext(int64(p.payloadLength))
|
p.payload = p.readStream.ReadBytesNext(int64(p.payloadLength))
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -219,10 +211,6 @@ func (p *PRUDPPacketV1) encodeHeader() []byte {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PRUDPPacketV1) decodeOptions() error {
|
func (p *PRUDPPacketV1) decodeOptions() error {
|
||||||
if p.readStream.Remaining() < uint64(p.optionsLength) {
|
|
||||||
return errors.New("Not have enough data")
|
|
||||||
}
|
|
||||||
|
|
||||||
data := p.readStream.ReadBytesNext(int64(p.optionsLength))
|
data := p.readStream.ReadBytesNext(int64(p.optionsLength))
|
||||||
optionsStream := NewByteStreamIn(data, p.server.LibraryVersions, p.server.ByteStreamSettings)
|
optionsStream := NewByteStreamIn(data, p.server.LibraryVersions, p.server.ByteStreamSettings)
|
||||||
|
|
||||||
|
@ -246,11 +234,7 @@ func (p *PRUDPPacketV1) decodeOptions() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if optionID == 1 {
|
if optionID == 1 {
|
||||||
if optionsStream.Remaining() < 16 {
|
p.connectionSignature = optionsStream.ReadBytesNext(16)
|
||||||
err = errors.New("Not have enough data")
|
|
||||||
} else {
|
|
||||||
p.connectionSignature = optionsStream.ReadBytesNext(16)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if optionID == 4 {
|
if optionID == 4 {
|
||||||
|
|
|
@ -127,11 +127,6 @@ func (ps *PRUDPServer) initPRUDPv1ConnectionSignatureKey() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ps *PRUDPServer) handleSocketMessage(packetData []byte, address net.Addr, webSocketConnection *gws.Conn) error {
|
func (ps *PRUDPServer) handleSocketMessage(packetData []byte, address net.Addr, webSocketConnection *gws.Conn) error {
|
||||||
// * Check that the message is long enough for initial parsing
|
|
||||||
if len(packetData) < 2 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
readStream := NewByteStreamIn(packetData, ps.LibraryVersions, ps.ByteStreamSettings)
|
readStream := NewByteStreamIn(packetData, ps.LibraryVersions, ps.ByteStreamSettings)
|
||||||
|
|
||||||
var packets []PRUDPPacketInterface
|
var packets []PRUDPPacketInterface
|
||||||
|
|
|
@ -643,7 +643,7 @@ func (s *StationURL) Parse() {
|
||||||
|
|
||||||
standardParameters := strings.Split(standardSection, ";")
|
standardParameters := strings.Split(standardSection, ";")
|
||||||
|
|
||||||
for i := range standardParameters {
|
for i := 0; i < len(standardParameters); i++ {
|
||||||
key, value, _ := strings.Cut(standardParameters[i], "=")
|
key, value, _ := strings.Cut(standardParameters[i], "=")
|
||||||
|
|
||||||
if key == "address" && len(value) > 256 {
|
if key == "address" && len(value) > 256 {
|
||||||
|
@ -662,14 +662,12 @@ func (s *StationURL) Parse() {
|
||||||
s.Set(key, value, false)
|
s.Set(key, value, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(customSection) != 0 {
|
customParameters := strings.Split(customSection, ";")
|
||||||
customParameters := strings.Split(customSection, ";")
|
|
||||||
|
|
||||||
for i := range customParameters {
|
for i := 0; i < len(customParameters); i++ {
|
||||||
key, value, _ := strings.Cut(customParameters[i], "=")
|
key, value, _ := strings.Cut(customParameters[i], "=")
|
||||||
|
|
||||||
s.Set(key, value, true)
|
s.Set(key, value, true)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if flags, ok := s.uint8ParamValue("type"); ok {
|
if flags, ok := s.uint8ParamValue("type"); ok {
|
||||||
|
@ -694,19 +692,6 @@ func (s *StationURL) Format() {
|
||||||
fields := make([]string, 0)
|
fields := make([]string, 0)
|
||||||
|
|
||||||
for key, value := range s.standardParams {
|
for key, value := range s.standardParams {
|
||||||
if key == "address" && len(value) > 256 {
|
|
||||||
// * The client can only hold a host name of up to 256 characters
|
|
||||||
// TODO - Should we return an error here?
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if key == "port" {
|
|
||||||
if port, err := strconv.Atoi(value); err != nil || (port < 0 || port > 65535) {
|
|
||||||
// TODO - Should we return an error here?
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fields = append(fields, fmt.Sprintf("%s=%s", key, value))
|
fields = append(fields, fmt.Sprintf("%s=%s", key, value))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -715,7 +700,20 @@ func (s *StationURL) Format() {
|
||||||
if len(s.customParams) != 0 {
|
if len(s.customParams) != 0 {
|
||||||
customFields := make([]string, 0)
|
customFields := make([]string, 0)
|
||||||
|
|
||||||
for key, value := range s.customParams {
|
for key, value := range s.standardParams {
|
||||||
|
if key == "address" && len(value) > 256 {
|
||||||
|
// * The client can only hold a host name of up to 256 characters
|
||||||
|
// TODO - Should we return an error here?
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if key == "port" {
|
||||||
|
if port, err := strconv.Atoi(value); err != nil || (port < 0 || port > 65535) {
|
||||||
|
// TODO - Should we return an error here?
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
customFields = append(customFields, fmt.Sprintf("%s=%s", key, value))
|
customFields = append(customFields, fmt.Sprintf("%s=%s", key, value))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue