Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ethcc #37

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions packages/network/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@
},
"type": "module",
"types": "./dist/src/index.d.ts",
"files": [
"src",
"dist",
"!dist/test",
"!**/*.tsbuildinfo"
],
"files": ["src", "dist", "!dist/test", "!**/*.tsbuildinfo"],
"exports": {
".": {
"types": "./dist/src/index.d.ts",
Expand Down
3 changes: 2 additions & 1 deletion packages/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@
"build": "tsc -b",
"clean": "rm -rf dist/ node_modules/",
"node": "tsx ./src/run_node.ts",
"node-ethcc": "tsx ./src/run_counter_splash.ts",
"prepack": "tsc -b",
"relay": "tsx ./src/run_relay.ts",
"start": "tsx ./src/index.ts",
"test": "vitest"
},
"devDependencies": {
"@types/node": "^20.14.2",
"tsx": "^4.16.0",
"tsx": "^4.15.6",
"typescript": "^5.4.5",
"vitest": "^1.6.0"
},
Expand Down
2 changes: 2 additions & 0 deletions packages/node/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export class TopologyNode {
await this._networkNode.start();

this._networkNode.addGroupMessageHandler((e) => {
console.log("Received message: ", e.detail);
if (e.detail.msg.topic === "_peer-discovery._p2p._pubsub") return;
// TODO: add base handler here after July demo
// send the events to the app handler
Expand All @@ -39,6 +40,7 @@ export class TopologyNode {
["/topology/message/0.0.1"],
async ({ stream }) => {
let input = await streamToString(stream);
console.log("Received message: ", input);
if (!input) return;

const message = JSON.parse(input);
Expand Down
56 changes: 56 additions & 0 deletions packages/node/src/objects/canvas.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { GSet } from "@topology-foundation/crdt";
import { TopologyObject } from "@topology-foundation/object";

export interface ICanvas extends TopologyObject {
width: number;
height: number;
sprays: GSet<String>;
addSpray(
timestamp: number,
offset: [number, number],
sprayType: number,
): void;
getSprays(): GSet<String>;
merge(peerCanvas: Canvas): void;
}

export class Canvas extends TopologyObject implements ICanvas {
width: number;
height: number;
sprays: GSet<String>;

constructor(
peerId: string,
width: number,
height: number,
sprays?: Set<String>,
) {
super(peerId);
this.width = width;
this.height = height;
this.sprays = new GSet<String>(sprays ? sprays : new Set<String>());
}

addSpray(
timestamp: number,
offset: [number, number],
sprayType: number,
): void {
if (
offset[0] < 0 ||
offset[0] >= this.width ||
offset[1] < 0 ||
offset[1] >= this.height
)
return;
this.sprays.add(`[${timestamp},[${offset[0]},${offset[1]}],${sprayType}]`);
}

getSprays(): GSet<String> {
return this.sprays;
}

merge(peerCanvas: Canvas): void {
this.sprays.merge(peerCanvas.getSprays());
}
}
14 changes: 14 additions & 0 deletions packages/node/src/run_counter_splash.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { TopologyNode } from ".";
import { Canvas } from "./objects/canvas";
import * as fs from "fs";

export async function start() {
const node = new TopologyNode();
await node.start();

let canvas = new Canvas(node.getPeerId(), 3000, 4000);
canvas.id = "topology::counter_splash";
node.createObject(canvas);
}

start();
2 changes: 1 addition & 1 deletion packages/object/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as crypto from "crypto";

export abstract class TopologyObject {
private abi?: string;
private id?: string;
id?: string;

constructor(peerId: string) {
this.abi = "";
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -978,9 +978,9 @@
integrity sha512-QvlqvYtGBYIDeO8dFdY4djkRubcrc+yTJtBc7n8VZPlJDUS/00A+PssbvERM8f9bYRmcaSEHPZgZojeQj7kzAA==

"@types/node@*", "@types/node@^20.14.2":
version "20.14.9"
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.14.9.tgz#12e8e765ab27f8c421a1820c99f5f313a933b420"
integrity sha512-06OCtnTXtWOZBJlRApleWndH4JsRVs1pDCc8dLSQp+7PpUpX3ePdHyeNSFTeSe7FtKyQkrlPvHwJOW3SLd8Oyg==
version "20.14.10"
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.14.10.tgz#a1a218290f1b6428682e3af044785e5874db469a"
integrity sha512-MdiXf+nDuMvY0gJKxyfZ7/6UFsETO7mGKF54MVD/ekJS6HdFtpZFBgrh6Pseu64XTb2MLyFPlbW6hj8HYRQNOQ==
dependencies:
undici-types "~5.26.4"

Expand Down Expand Up @@ -3722,7 +3722,7 @@ tslib@^2.0.1, tslib@^2.1.0, tslib@^2.4.0, tslib@^2.6.1:
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.6.3.tgz#0438f810ad7a9edcde7a241c3d80db693c8cbfe0"
integrity sha512-xNvxJEOUiWPGhUuUdQgAJPKOOJfGnIyKySOc09XkKsgdUV/3E2zvwZYdejjmRgPCgcym1juLH3226yA7sEFJKQ==

tsx@^4.16.0:
tsx@^4.15.6:
version "4.16.2"
resolved "https://registry.yarnpkg.com/tsx/-/tsx-4.16.2.tgz#8722be119ae226ef0b4c6210d5ee90f3ba823f19"
integrity sha512-C1uWweJDgdtX2x600HjaFaucXTilT7tgUZHbOE4+ypskZ1OP8CRCSDkCxG6Vya9EwaFIVagWwpaVAn5wzypaqQ==
Expand Down