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

NAT traversal via Rendezvous protocol #228

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
19 changes: 19 additions & 0 deletions src/message/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
INodesMessage,
ITalkReqMessage,
ITalkRespMessage,
IRelayRequestMessage,
IRelayResponseMessage,
} from "./types.js";
import { SequenceNumber, ENR } from "../enr/index.js";

Expand Down Expand Up @@ -56,3 +58,20 @@ export function createTalkResponseMessage(requestId: RequestId, payload: Uint8Ar
response: Buffer.from(payload),
};
}

export function createRelayRequestMessage(fromNodeId: bigint, toNodeId: bigint): IRelayRequestMessage {
return {
type: MessageType.RELAYREQUEST,
id: createRequestId(),
fromNodeId,
toNodeId,
};
}

export function createRelayResponseMessage(response: number): IRelayResponseMessage {
return {
type: MessageType.RELAYRESPONSE,
id: createRequestId(),
response,
};
}
26 changes: 24 additions & 2 deletions src/message/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export enum MessageType {
TICKET = 8,
REGCONFIRMATION = 9,
TOPICQUERY = 10,
RELAYREQUEST = 11,
RELAYRESPONSE = 12,
}

export function isRequestType(type: MessageType): boolean {
Expand All @@ -34,14 +36,21 @@ export function isRequestType(type: MessageType): boolean {

export type Message = RequestMessage | ResponseMessage;

export type RequestMessage = IPingMessage | IFindNodeMessage | ITalkReqMessage | IRegTopicMessage | ITopicQueryMessage;
export type RequestMessage =
| IPingMessage
| IFindNodeMessage
| ITalkReqMessage
| IRegTopicMessage
| ITopicQueryMessage
| IRelayResponseMessage;

export type ResponseMessage =
| IPongMessage
| INodesMessage
| ITalkRespMessage
| ITicketMessage
| IRegConfirmationMessage;
| IRegConfirmationMessage
| IRelayResponseMessage;

export interface IPingMessage {
type: MessageType.PING;
Expand Down Expand Up @@ -108,3 +117,16 @@ export interface ITopicQueryMessage {
id: RequestId;
topic: Buffer;
}

export interface IRelayRequestMessage {
type: MessageType.RELAYREQUEST;
id: RequestId;
fromNodeId: bigint;
toNodeId: bigint;
}

export interface IRelayResponseMessage {
type: MessageType.RELAYRESPONSE;
id: RequestId;
response: number;
}