Skip to content

Commit

Permalink
return back to v1.12.4
Browse files Browse the repository at this point in the history
  • Loading branch information
mikhaillav committed Nov 7, 2023
1 parent a89d9c4 commit 3a581c7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
4 changes: 2 additions & 2 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const (
// currentProtocol is the current RakNet protocol version. This is Minecraft specific.
currentProtocol byte = 11

maxMTUSize = 9000
maxMTUSize = 1400
maxWindowSize = 2048
)

Expand Down Expand Up @@ -88,7 +88,7 @@ func newConn(conn net.PacketConn, addr net.Addr, mtuSize uint16) *Conn {
// if the connection should limit the bounds of things such as the size of packets. This is generally recommended for
// connections coming from a client.
func newConnWithLimits(conn net.PacketConn, addr net.Addr, mtuSize uint16, limits bool) *Conn {
if mtuSize < 500 || mtuSize > 9000 {
if mtuSize < 500 || mtuSize > 1500 {
mtuSize = maxMTUSize
}
c := &Conn{
Expand Down
12 changes: 6 additions & 6 deletions dial.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func (dialer Dialer) PingContext(ctx context.Context, address string) (response
}
buffer.Reset()

data := make([]byte, 9000)
data := make([]byte, 1492)
n, err := conn.Read(data)
if err != nil {
return nil, &net.OpError{Op: "ping", Net: "raknet", Source: nil, Addr: nil, Err: actual(err)}
Expand Down Expand Up @@ -226,7 +226,7 @@ func (dialer Dialer) DialContext(ctx context.Context, address string) (*Conn, er
state := &connState{
conn: udpConn,
remoteAddr: udpConn.RemoteAddr(),
discoveringMTUSize: 9000,
discoveringMTUSize: 1492,
id: id,
}
wrap := func(ctx context.Context, err error) error {
Expand Down Expand Up @@ -277,7 +277,7 @@ func (conn *wrappedConn) WriteTo(b []byte, _ net.Addr) (n int, err error) {
func clientListen(rakConn *Conn, conn net.Conn, errorLog *log.Logger) {
// Create a buffer with the maximum size a UDP packet sent over RakNet is allowed to have. We can re-use
// this buffer for each packet.
b := make([]byte, 9000)
b := make([]byte, 1500)
buf := bytes.NewBuffer(b[:0])
for {
n, err := conn.Read(b)
Expand Down Expand Up @@ -345,7 +345,7 @@ func (state *connState) openConnectionRequest(ctx context.Context) (e error) {
}
}()

b := make([]byte, 9000)
b := make([]byte, 1492)
for {
// Start reading in a loop so that we can find open connection reply 2 packets.
n, err := state.conn.Read(b)
Expand Down Expand Up @@ -413,7 +413,7 @@ func (state *connState) discoverMTUSize(ctx context.Context) (e error) {
}
}()

b := make([]byte, 9000)
b := make([]byte, 1492)
for {
// Start reading in a loop so that we can find open connection reply 1 packets.
n, err := state.conn.Read(b)
Expand All @@ -431,7 +431,7 @@ func (state *connState) discoverMTUSize(ctx context.Context) (e error) {
if err := response.Read(buffer); err != nil {
return fmt.Errorf("error reading open connection reply 1: %v", err)
}
if response.ServerPreferredMTUSize < 400 || response.ServerPreferredMTUSize > 9000 {
if response.ServerPreferredMTUSize < 400 || response.ServerPreferredMTUSize > 1500 {
// This is an awful hack we cooked up to deal with OVH 'DDoS' protection. For some reason they
// send a broken MTU size first. Sending a Request2 followed by a Request1 deals with this.
_ = state.sendOpenConnectionRequest2(response.ServerPreferredMTUSize)
Expand Down
4 changes: 1 addition & 3 deletions listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,7 @@ func (listener *Listener) listen() {

// Technically we should not re-use the same byte slice after its ownership has been taken by the
// buffer, but we can do this anyway because we copy the data later.
if err := listener.handle(buf, addr); err != nil {
listener.log.Printf("listener: error handling packet (addr = %v): %v\n", addr, err)
}
listener.handle(buf, addr)
buf.Reset()
}
}
Expand Down

0 comments on commit 3a581c7

Please sign in to comment.