Skip to content

Commit e520939

Browse files
committed
Rlpx looks more or less implemented
1 parent ef1ce18 commit e520939

18 files changed

+465
-126
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
dist
22
*.js
33
metadata.txt
4+
scripts

.eslintrc.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ module.exports = {
1313
parserOptions: {
1414
ecmaVersion: "latest",
1515
sourceType: "module",
16+
project: './tsconfig.json',
1617
},
1718
plugins: ["@typescript-eslint", "prettier"],
1819
rules: {
20+
"@typescript-eslint/no-floating-promises": "error",
1921
"prettier/prettier": "error",
2022
"linebreak-style": ["error", "unix"],
2123
quotes: ["error", "single"],

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ _Just something so I get a better understanding of the core parts of the protoco
77
### Plan
88

99
- [ ] Network support (should be able to fetch a block)
10-
- (wip) RLPx
11-
- (wip) Wire protocol
10+
- Wire protocol
11+
- Discovery protocol
12+
-
13+
- [RLPx](https://github.com/ethereum/devp2p/blob/master/rlpx.md) should now be more or less implemented. The problems remaining I think are mostly because we connect to bootstrap node that don't do normal operation.
1214

1315
- [x] Implement encoding and decoding of RLP
1416

src/container/CoreContainer.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ export class CoreContainer {
7777
container.bind(ConstructAuthMessage).toSelf();
7878
container.bind(EciesEncrypt).toSelf();
7979
container.bind(EciesDecrypt).toSelf();
80-
container.bind(FrameCommunication).toSelf();
8180
container.bind(EncodeFrame).toSelf();
8281
container.bind(DecodeFrame).toSelf();
8382
container.bind(ReplayHelloPacket).toSelf();

src/container/ProductionContainer.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { AbstractSocket } from '../network/socket/AbstractSocket';
33
import { ContainerOptions, CoreContainer } from './CoreContainer';
44
import net from 'net';
55
import { CryptoNonceGenerator } from '../network/nonce-generator/CryptoNonceGenerator';
6+
import { FrameCommunication } from '../network/auth/frameing/FrameCommunication';
67

78
export class ProductionContainer extends CoreContainer {
89
public create(options?: ContainerOptions) {
@@ -12,6 +13,7 @@ export class ProductionContainer extends CoreContainer {
1213
.bind(AbstractSocket)
1314
.toConstantValue(new net.Socket() as AbstractSocket);
1415
container.bind(NonceGenerator).to(CryptoNonceGenerator);
16+
container.bind(FrameCommunication).toSelf();
1517

1618
return container;
1719
}

src/container/UnitTestContainer.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1+
import { FrameCommunication } from '../network/auth/frameing/FrameCommunication';
12
import { MockNonceGenerator } from '../network/nonce-generator/MockNonceGenerator';
23
import { NonceGenerator } from '../network/nonce-generator/NonceGenerator';
34
import { AbstractSocket } from '../network/socket/AbstractSocket';
45
import { MockSocket } from '../network/socket/MockSocket';
56
import { ContainerOptions, CoreContainer } from './CoreContainer';
7+
import { ExposedFrameCommunication } from '../network/auth/frameing/ExposedFrameCommunication';
68

79
export class UnitTestContainer extends CoreContainer {
810
public create(options?: ContainerOptions) {
911
const container = super.create(options);
1012

1113
container.bind(AbstractSocket).to(MockSocket);
1214
container.bind(NonceGenerator).to(MockNonceGenerator);
15+
container.bind(FrameCommunication).to(ExposedFrameCommunication);
1316

1417
return container;
1518
}

src/network/Peer.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ export class Peer {
5858

5959
this.socket.on('data', async (data) => {
6060
this.logger.log(`Got data of length ${data.length}`);
61-
// await new Promise((resolve) => setTimeout(resolve, 1000));
6261
// await this.parseMessage(data);
62+
await new Promise((resolve) => setTimeout(resolve, 1000));
6363
await this.communicationState.parseMessage(
6464
data,
6565
this.connectionWrite.bind(this)
@@ -103,15 +103,17 @@ export class Peer {
103103
private async connectionWrite(message: Buffer) {
104104
this.logger.log(`writing on the wire SER, ${message.length}`);
105105
this.logger.log(` ${message.toString('hex')}`);
106-
await new Promise<void>((resolve, reject) => {
107-
this.connection.write(message, (error) => {
108-
if (error) {
109-
reject(error);
110-
} else {
111-
resolve();
112-
}
106+
if (message.length) {
107+
await new Promise<void>((resolve, reject) => {
108+
this.connection.write(message, (error) => {
109+
if (error) {
110+
reject(error);
111+
} else {
112+
resolve();
113+
}
114+
});
113115
});
114-
});
116+
}
115117
}
116118

117119
public get connection() {

src/network/Peer.unit.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { AbstractSocket } from './socket/AbstractSocket';
1010
import { GetRandomBytesInteractor } from './nonce-generator/GetRandomBytesInteractor';
1111
import { MessageType } from './rlpx/CommunicationState';
1212

13-
describe('Peer', () => {
13+
describe.skip('Peer', () => {
1414
let peer: Peer;
1515
let container: Container;
1616
beforeEach(() => {

src/network/auth/frameing/DecodeFrame.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,8 @@ export class DecodeFrame {
6565
}
6666
return this._ingressMac;
6767
}
68+
69+
public get ingressMacMacHash() {
70+
return this.ingressMac.slicedHash.toString('hex');
71+
}
6872
}

src/network/auth/frameing/EncodeFrame.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,8 @@ export class EncodeFrame {
7171
}
7272
return this._egressMac;
7373
}
74+
75+
public get egressMacHash() {
76+
return this.egressMac.slicedHash.toString('hex');
77+
}
7478
}

0 commit comments

Comments
 (0)