Skip to content

Use byte buffer for packets to avoid copying#46

Open
jon-zu wants to merge 4 commits intodoriyan13:masterfrom
jon-zu:jz/netty-byte-buf
Open

Use byte buffer for packets to avoid copying#46
jon-zu wants to merge 4 commits intodoriyan13:masterfrom
jon-zu:jz/netty-byte-buf

Conversation

@jon-zu
Copy link

@jon-zu jon-zu commented Mar 2, 2024

Groundwork to use netty byte bufs for packets properly. Not done yet(!)

  • Use ByteBuf in packet
  • Make Packets basically immutable, after sending(maybe add a special type)
  • Create a proper channel handler
  • Test against live client
  • Unit tests
  • Ref Count Test

Copy link
Owner

@doriyan13 doriyan13 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for all the comments, tho i'm rlly excited about this changes! :D
rlly nice job Joo! <3

}

static void decryptData(ByteBuf buf,
int offset,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the offset is always 0, please inline it. no need for it to be a param.

private static Cipher initCipher() {
try {
cipher = Cipher.getInstance("AES");
Cipher cipher = Cipher.getInstance("AES");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the old algo, please update to the new one.
i don't remember if i pushed it to master but it's in dev for sure

// Init connection for the client -
logger.serverNotice(String.format("[CHAT] Opened session with %s in Acceptor", c.getIP()));
c.write(CLogin.sendConnect(siv,riv));
c.write(CLogin.sendConnect(siv.getBytes(), riv.getBytes()));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

your Initialization vector save int and start convert to bytes each time you call getBytes, it's redundant and expensive thus i've removed it and kept it as byte array

logger.notice(String.format("Channel %d-%d listening on port %d", channel.getWorldId(), channel.getChannelId(), channel.getPort()));
if (channel != null) {
logger.notice(String.format("Channel %d-%d listening on port %d", channel.getWorldId(),
channel.getChannelId(), channel.getPort()));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnecessary dropping line


import com.dori.SpringStory.connection.packet.OutPacket;

public class BroadcastSet<T extends NettyClient> {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after thinking on what you said yesterday -
we can just keep the lock as static rather then instance base and each time you get to the encoder - call this util class that will lock, get list of clients and then do the same business logic

@Override
public String toString() {
return MapleUtils.readableByteArray(Arrays.copyOfRange(getData(), getData().length - getUnreadAmount(), getData().length)); // Substring after copy of range xd
return super.toString();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i use the toString to log all the packets, please make sure this logic still being printed as intend


@Override
public String toString() {
return "[Pck] | " + this.buf.toString();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeh this is not good, please use my handling for toString or just remove the prefix of [Pck]

// If it's true will auto login as admin -
if (AUTO_LOGIN) {
OutPacket outPacket = new OutPacket();
OutPacket outPacket = new OutPacket(0);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeh it's bad practice, default 0 should be internal and not be passed into constructor in java

private long creationTime;
private long deprecationStartTime;
private List<PositionData> mobsSpawnPoints = new ArrayList<>();
private BroadcastSet<MapleClient> tx = new BroadcastSet<>();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will require double maintaining which i think is redundant

this.needSkillForFly = mapData.isNeedSkillForFly();
this.fixedMobCapacity = mapData.getFixedMobCapacity() != 0 ? mapData.getFixedMobCapacity() : DEFAULT_FIELD_MOB_CAPACITY;
this.fixedMobCapacity = mapData.getFixedMobCapacity() != 0 ? mapData.getFixedMobCapacity()
: DEFAULT_FIELD_MOB_CAPACITY;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in java it's suppose to be inline

@doriyan13 doriyan13 assigned doriyan13 and jon-zu and unassigned doriyan13 Mar 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants