Skip to content

Commit

Permalink
udpate protocol to handle multiple address
Browse files Browse the repository at this point in the history
  • Loading branch information
gonpombo8 committed Jan 13, 2025
1 parent 3bd2c88 commit bb03f3a
Show file tree
Hide file tree
Showing 16 changed files with 52 additions and 55 deletions.
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"bugs": "https://github.com/decentraland/js-sdk-toolchain/issues",
"dependencies": {
"@actions/core": "^1.10.0",
"@dcl/protocol": "https://sdk-team-cdn.decentraland.org/@dcl/protocol/branch//dcl-protocol-1.0.0-12687285199.commit-5a8c3ae.tgz",
"@dcl/protocol": "https://sdk-team-cdn.decentraland.org/@dcl/protocol/branch//dcl-protocol-1.0.0-12754011500.commit-762ebe6.tgz",
"@dcl/quickjs-emscripten": "^0.21.0-3680274614.commit-1808aa1",
"@dcl/ts-proto": "1.153.0",
"@types/fs-extra": "^9.0.12",
Expand Down
6 changes: 4 additions & 2 deletions packages/@dcl/sdk/src/network/binary-message-bus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ export enum CommsMessage {
RES_CRDT_STATE = 3
}

export function BinaryMessageBus<T extends CommsMessage>(send: (message: Uint8Array, toPeerAddress?: string) => void) {
export function BinaryMessageBus<T extends CommsMessage>(
send: (message: Uint8Array, toPeerAddress?: string[]) => void
) {
const mapping: Map<T, (value: Uint8Array, sender: string) => void> = new Map()
return {
on: <K extends T>(message: K, callback: (value: Uint8Array, sender: string) => void) => {
mapping.set(message, callback)
},
emit: <K extends T>(message: K, value: Uint8Array, toPeerAddress?: string) => {
emit: <K extends T>(message: K, value: Uint8Array, toPeerAddress?: string[]) => {
send(craftCommsMessage<T>(message, value), toPeerAddress)
},
__processMessages: (messages: Uint8Array[]) => {
Expand Down
13 changes: 4 additions & 9 deletions packages/@dcl/sdk/src/network/message-bus-sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,10 @@ export function addSyncTransport(
const entityDefinitions = entityUtils(engine, myProfile)

// List of MessageBuss messsages to be sent on every frame to comms
const pendingMessageBusMessagesToSend: { data: Uint8Array[]; address: string }[] = []
const pendingMessageBusMessagesToSend: { data: Uint8Array[]; address: string[] }[] = []

const binaryMessageBus = BinaryMessageBus((data, address) => {
const pendingAddressMessage = address && pendingMessageBusMessagesToSend.find(($) => $.address === address)
if (pendingAddressMessage) {
pendingAddressMessage.data.push(data)
} else {
pendingMessageBusMessagesToSend.push({ data: [data], address: address ?? '' })
}
pendingMessageBusMessagesToSend.push({ data: [data], address: address ?? [] })
})

function getMessagesToSend(): [Uint8Array[], typeof pendingMessageBusMessagesToSend] {
Expand All @@ -44,7 +39,7 @@ export function addSyncTransport(
const peerMessages: typeof pendingMessageBusMessagesToSend = []

for (const message of messages) {
if (!message.address) {
if (!message.address.length) {
broadcastMessages.push(...message.data)
} else {
peerMessages.push(message)
Expand Down Expand Up @@ -90,7 +85,7 @@ export function addSyncTransport(
binaryMessageBus.on(CommsMessage.REQ_CRDT_STATE, async (message, userId) => {
console.log(`Sending CRDT State to: ${userId}`)
transport.onmessage!(message)
binaryMessageBus.emit(CommsMessage.RES_CRDT_STATE, encodeCRDTState(userId, engineToCrdt(engine)), userId)
binaryMessageBus.emit(CommsMessage.RES_CRDT_STATE, encodeCRDTState(userId, engineToCrdt(engine)), [userId])
})

// Process CRDT messages here
Expand Down
6 changes: 3 additions & 3 deletions test/snapshots/development-bundles/static-scene.test.ts.crdt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SCENE_COMPILED_JS_SIZE_PROD=455.7k bytes
SCENE_COMPILED_JS_SIZE_PROD=456k bytes
THE BUNDLE HAS SOURCEMAPS
(start empty vm 0.21.0-3680274614.commit-1808aa1)
OPCODES ~= 0k
Expand All @@ -11,7 +11,7 @@ EVAL test/snapshots/development-bundles/static-scene.test.js
REQUIRE: ~system/EngineApi
REQUIRE: ~system/EngineApi
OPCODES ~= 54k
MALLOC_COUNT = 13700
MALLOC_COUNT = 13705
ALIVE_OBJS_DELTA ~= 2.70k
CALL onStart()
main.crdt: PUT_COMPONENT e=0x200 c=1 t=0 data={"position":{"x":5.880000114440918,"y":2.7916901111602783,"z":7.380000114440918},"rotation":{"x":0,"y":0,"z":0,"w":1},"scale":{"x":1,"y":1,"z":1},"parent":0}
Expand Down Expand Up @@ -56,4 +56,4 @@ CALL onUpdate(0.1)
OPCODES ~= 3k
MALLOC_COUNT = -5
ALIVE_OBJS_DELTA ~= 0.00k
MEMORY_USAGE_COUNT ~= 1198.40k bytes
MEMORY_USAGE_COUNT ~= 1199.30k bytes
6 changes: 3 additions & 3 deletions test/snapshots/development-bundles/testing-fw.test.ts.crdt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SCENE_COMPILED_JS_SIZE_PROD=456.2k bytes
SCENE_COMPILED_JS_SIZE_PROD=456.5k bytes
THE BUNDLE HAS SOURCEMAPS
(start empty vm 0.21.0-3680274614.commit-1808aa1)
OPCODES ~= 0k
Expand All @@ -11,7 +11,7 @@ EVAL test/snapshots/development-bundles/testing-fw.test.js
REQUIRE: ~system/EngineApi
REQUIRE: ~system/EngineApi
OPCODES ~= 63k
MALLOC_COUNT = 14221
MALLOC_COUNT = 14226
ALIVE_OBJS_DELTA ~= 2.85k
CALL onStart()
LOG: ["Adding one to position.y=0"]
Expand Down Expand Up @@ -64,4 +64,4 @@ CALL onUpdate(0.1)
OPCODES ~= 5k
MALLOC_COUNT = -40
ALIVE_OBJS_DELTA ~= -0.01k
MEMORY_USAGE_COUNT ~= 1207.01k bytes
MEMORY_USAGE_COUNT ~= 1207.91k bytes
6 changes: 3 additions & 3 deletions test/snapshots/development-bundles/two-way-crdt.test.ts.crdt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SCENE_COMPILED_JS_SIZE_PROD=456.2k bytes
SCENE_COMPILED_JS_SIZE_PROD=456.5k bytes
THE BUNDLE HAS SOURCEMAPS
(start empty vm 0.21.0-3680274614.commit-1808aa1)
OPCODES ~= 0k
Expand All @@ -11,7 +11,7 @@ EVAL test/snapshots/development-bundles/two-way-crdt.test.js
REQUIRE: ~system/EngineApi
REQUIRE: ~system/EngineApi
OPCODES ~= 63k
MALLOC_COUNT = 14221
MALLOC_COUNT = 14226
ALIVE_OBJS_DELTA ~= 2.85k
CALL onStart()
LOG: ["Adding one to position.y=0"]
Expand Down Expand Up @@ -64,4 +64,4 @@ CALL onUpdate(0.1)
OPCODES ~= 5k
MALLOC_COUNT = -40
ALIVE_OBJS_DELTA ~= -0.01k
MEMORY_USAGE_COUNT ~= 1207.02k bytes
MEMORY_USAGE_COUNT ~= 1207.92k bytes
6 changes: 3 additions & 3 deletions test/snapshots/production-bundles/append-value-crdt.ts.crdt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SCENE_COMPILED_JS_SIZE_PROD=199.2k bytes
SCENE_COMPILED_JS_SIZE_PROD=199.4k bytes
(start empty vm 0.21.0-3680274614.commit-1808aa1)
OPCODES ~= 0k
MALLOC_COUNT = 1005
Expand All @@ -9,7 +9,7 @@ EVAL test/snapshots/production-bundles/append-value-crdt.js
REQUIRE: ~system/EngineApi
REQUIRE: ~system/EngineApi
OPCODES ~= 65k
MALLOC_COUNT = 12748
MALLOC_COUNT = 12753
ALIVE_OBJS_DELTA ~= 2.85k
CALL onStart()
Renderer: APPEND_VALUE e=0x200 c=1063 t=0 data={"button":0,"hit":{"position":{"x":1,"y":2,"z":3},"globalOrigin":{"x":1,"y":2,"z":3},"direction":{"x":1,"y":2,"z":3},"normalHit":{"x":1,"y":2,"z":3},"length":10,"meshName":"mesh","entityId":512},"state":1,"timestamp":1,"analog":5,"tickNumber":0}
Expand Down Expand Up @@ -55,4 +55,4 @@ CALL onUpdate(0.1)
OPCODES ~= 14k
MALLOC_COUNT = 31
ALIVE_OBJS_DELTA ~= 0.01k
MEMORY_USAGE_COUNT ~= 902.35k bytes
MEMORY_USAGE_COUNT ~= 903.06k bytes
8 changes: 4 additions & 4 deletions test/snapshots/production-bundles/billboard.ts.crdt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SCENE_COMPILED_JS_SIZE_PROD=232.2k bytes
SCENE_COMPILED_JS_SIZE_PROD=232.4k bytes
(start empty vm 0.21.0-3680274614.commit-1808aa1)
OPCODES ~= 0k
MALLOC_COUNT = 1005
Expand All @@ -9,8 +9,8 @@ EVAL test/snapshots/production-bundles/billboard.js
REQUIRE: ~system/EngineApi
REQUIRE: ~system/EngineApi
OPCODES ~= 66k
MALLOC_COUNT = 14860
ALIVE_OBJS_DELTA ~= 3.24k
MALLOC_COUNT = 14865
ALIVE_OBJS_DELTA ~= 3.25k
CALL onStart()
OPCODES ~= 0k
MALLOC_COUNT = 4
Expand Down Expand Up @@ -77,4 +77,4 @@ CALL onUpdate(0.1)
OPCODES ~= 10k
MALLOC_COUNT = 0
ALIVE_OBJS_DELTA ~= 0.00k
MEMORY_USAGE_COUNT ~= 1044.69k bytes
MEMORY_USAGE_COUNT ~= 1045.40k bytes
6 changes: 3 additions & 3 deletions test/snapshots/production-bundles/cube-deleted.ts.crdt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SCENE_COMPILED_JS_SIZE_PROD=195.4k bytes
SCENE_COMPILED_JS_SIZE_PROD=195.6k bytes
(start empty vm 0.21.0-3680274614.commit-1808aa1)
OPCODES ~= 0k
MALLOC_COUNT = 1005
Expand All @@ -9,7 +9,7 @@ EVAL test/snapshots/production-bundles/cube-deleted.js
REQUIRE: ~system/EngineApi
REQUIRE: ~system/EngineApi
OPCODES ~= 55k
MALLOC_COUNT = 11902
MALLOC_COUNT = 11907
ALIVE_OBJS_DELTA ~= 2.63k
CALL onStart()
OPCODES ~= 0k
Expand Down Expand Up @@ -42,4 +42,4 @@ CALL onUpdate(0.1)
OPCODES ~= 5k
MALLOC_COUNT = 1
ALIVE_OBJS_DELTA ~= 0.00k
MEMORY_USAGE_COUNT ~= 865.07k bytes
MEMORY_USAGE_COUNT ~= 865.78k bytes
6 changes: 3 additions & 3 deletions test/snapshots/production-bundles/cube.ts.crdt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SCENE_COMPILED_JS_SIZE_PROD=195.3k bytes
SCENE_COMPILED_JS_SIZE_PROD=195.5k bytes
(start empty vm 0.21.0-3680274614.commit-1808aa1)
OPCODES ~= 0k
MALLOC_COUNT = 1005
Expand All @@ -9,7 +9,7 @@ EVAL test/snapshots/production-bundles/cube.js
REQUIRE: ~system/EngineApi
REQUIRE: ~system/EngineApi
OPCODES ~= 55k
MALLOC_COUNT = 11875
MALLOC_COUNT = 11880
ALIVE_OBJS_DELTA ~= 2.62k
CALL onStart()
OPCODES ~= 0k
Expand All @@ -32,4 +32,4 @@ CALL onUpdate(0.1)
OPCODES ~= 1k
MALLOC_COUNT = 0
ALIVE_OBJS_DELTA ~= 0.00k
MEMORY_USAGE_COUNT ~= 854.99k bytes
MEMORY_USAGE_COUNT ~= 855.70k bytes
6 changes: 3 additions & 3 deletions test/snapshots/production-bundles/cubes.ts.crdt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SCENE_COMPILED_JS_SIZE_PROD=232.6k bytes
SCENE_COMPILED_JS_SIZE_PROD=232.8k bytes
(start empty vm 0.21.0-3680274614.commit-1808aa1)
OPCODES ~= 0k
MALLOC_COUNT = 1005
Expand All @@ -9,7 +9,7 @@ EVAL test/snapshots/production-bundles/cubes.js
REQUIRE: ~system/EngineApi
REQUIRE: ~system/EngineApi
OPCODES ~= 105k
MALLOC_COUNT = 18202
MALLOC_COUNT = 18207
ALIVE_OBJS_DELTA ~= 4.53k
CALL onStart()
OPCODES ~= 0k
Expand Down Expand Up @@ -1652,4 +1652,4 @@ CALL onUpdate(0.1)
OPCODES ~= 692k
MALLOC_COUNT = 0
ALIVE_OBJS_DELTA ~= 0.00k
MEMORY_USAGE_COUNT ~= 1180.62k bytes
MEMORY_USAGE_COUNT ~= 1181.33k bytes
6 changes: 3 additions & 3 deletions test/snapshots/production-bundles/pointer-events.ts.crdt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SCENE_COMPILED_JS_SIZE_PROD=196.2k bytes
SCENE_COMPILED_JS_SIZE_PROD=196.4k bytes
(start empty vm 0.21.0-3680274614.commit-1808aa1)
OPCODES ~= 0k
MALLOC_COUNT = 1005
Expand All @@ -9,7 +9,7 @@ EVAL test/snapshots/production-bundles/pointer-events.js
REQUIRE: ~system/EngineApi
REQUIRE: ~system/EngineApi
OPCODES ~= 56k
MALLOC_COUNT = 12161
MALLOC_COUNT = 12166
ALIVE_OBJS_DELTA ~= 2.70k
CALL onStart()
OPCODES ~= 0k
Expand Down Expand Up @@ -43,4 +43,4 @@ CALL onUpdate(0.1)
OPCODES ~= 1k
MALLOC_COUNT = 0
ALIVE_OBJS_DELTA ~= 0.00k
MEMORY_USAGE_COUNT ~= 872.71k bytes
MEMORY_USAGE_COUNT ~= 873.43k bytes
6 changes: 3 additions & 3 deletions test/snapshots/production-bundles/schema-components.ts.crdt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SCENE_COMPILED_JS_SIZE_PROD=195.3k bytes
SCENE_COMPILED_JS_SIZE_PROD=195.5k bytes
(start empty vm 0.21.0-3680274614.commit-1808aa1)
OPCODES ~= 0k
MALLOC_COUNT = 1005
Expand All @@ -9,7 +9,7 @@ EVAL test/snapshots/production-bundles/schema-components.js
REQUIRE: ~system/EngineApi
REQUIRE: ~system/EngineApi
OPCODES ~= 59k
MALLOC_COUNT = 12002
MALLOC_COUNT = 12007
ALIVE_OBJS_DELTA ~= 2.65k
CALL onStart()
OPCODES ~= 0k
Expand All @@ -31,4 +31,4 @@ CALL onUpdate(0.1)
OPCODES ~= 1k
MALLOC_COUNT = 0
ALIVE_OBJS_DELTA ~= 0.00k
MEMORY_USAGE_COUNT ~= 857.41k bytes
MEMORY_USAGE_COUNT ~= 858.12k bytes
6 changes: 3 additions & 3 deletions test/snapshots/production-bundles/ui.ts.crdt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SCENE_COMPILED_JS_SIZE_PROD=353.5k bytes
SCENE_COMPILED_JS_SIZE_PROD=353.7k bytes
(start empty vm 0.21.0-3680274614.commit-1808aa1)
OPCODES ~= 0k
MALLOC_COUNT = 1005
Expand All @@ -9,7 +9,7 @@ EVAL test/snapshots/production-bundles/ui.js
REQUIRE: ~system/EngineApi
REQUIRE: ~system/EngineApi
OPCODES ~= 65k
MALLOC_COUNT = 19502
MALLOC_COUNT = 19507
ALIVE_OBJS_DELTA ~= 3.88k
CALL onStart()
OPCODES ~= 0k
Expand Down Expand Up @@ -65,4 +65,4 @@ CALL onUpdate(0.1)
OPCODES ~= 64k
MALLOC_COUNT = 0
ALIVE_OBJS_DELTA ~= 0.00k
MEMORY_USAGE_COUNT ~= 1694.71k bytes
MEMORY_USAGE_COUNT ~= 1695.42k bytes
6 changes: 3 additions & 3 deletions test/snapshots/production-bundles/with-main-function.ts.crdt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SCENE_COMPILED_JS_SIZE_PROD=196k bytes
SCENE_COMPILED_JS_SIZE_PROD=196.2k bytes
(start empty vm 0.21.0-3680274614.commit-1808aa1)
OPCODES ~= 0k
MALLOC_COUNT = 1005
Expand All @@ -9,7 +9,7 @@ EVAL test/snapshots/production-bundles/with-main-function.js
REQUIRE: ~system/EngineApi
REQUIRE: ~system/EngineApi
OPCODES ~= 55k
MALLOC_COUNT = 12031
MALLOC_COUNT = 12036
ALIVE_OBJS_DELTA ~= 2.65k
CALL onStart()
OPCODES ~= 0k
Expand Down Expand Up @@ -37,4 +37,4 @@ CALL onUpdate(0.1)
OPCODES ~= 3k
MALLOC_COUNT = 5
ALIVE_OBJS_DELTA ~= 0.00k
MEMORY_USAGE_COUNT ~= 870.53k bytes
MEMORY_USAGE_COUNT ~= 871.24k bytes

0 comments on commit bb03f3a

Please sign in to comment.