This repository has been archived by the owner on Jul 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allows tagging peers to mark some important or ones we should keep connections open to, etc. Depends on: - [ ] libp2p/js-libp2p-interfaces#255 Refs: libp2p/js-libp2p#369
- Loading branch information
1 parent
a50f109
commit 8aaf09f
Showing
5 changed files
with
235 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
syntax = "proto3"; | ||
|
||
message Tags { | ||
repeated Tag tags = 1; | ||
} | ||
|
||
message Tag { | ||
string name = 1; // e.g. 'priority' | ||
optional uint32 value = 2; // tag value 0-100 | ||
optional uint64 expiry = 3; // ms timestamp after which the tag is no longer valid | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* eslint-disable import/export */ | ||
/* eslint-disable @typescript-eslint/no-namespace */ | ||
|
||
import { encodeMessage, decodeMessage, message, string, uint32, uint64 } from 'protons-runtime' | ||
import type { Codec } from 'protons-runtime' | ||
|
||
export interface Tags { | ||
tags: Tag[] | ||
} | ||
|
||
export namespace Tags { | ||
export const codec = (): Codec<Tags> => { | ||
return message<Tags>({ | ||
1: { name: 'tags', codec: Tag.codec(), repeats: true } | ||
}) | ||
} | ||
|
||
export const encode = (obj: Tags): Uint8Array => { | ||
return encodeMessage(obj, Tags.codec()) | ||
} | ||
|
||
export const decode = (buf: Uint8Array): Tags => { | ||
return decodeMessage(buf, Tags.codec()) | ||
} | ||
} | ||
|
||
export interface Tag { | ||
name: string | ||
value?: number | ||
expiry?: bigint | ||
} | ||
|
||
export namespace Tag { | ||
export const codec = (): Codec<Tag> => { | ||
return message<Tag>({ | ||
1: { name: 'name', codec: string }, | ||
2: { name: 'value', codec: uint32, optional: true }, | ||
3: { name: 'expiry', codec: uint64, optional: true } | ||
}) | ||
} | ||
|
||
export const encode = (obj: Tag): Uint8Array => { | ||
return encodeMessage(obj, Tag.codec()) | ||
} | ||
|
||
export const decode = (buf: Uint8Array): Tag => { | ||
return decodeMessage(buf, Tag.codec()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters