From 55ca6a4e6f70f11a44a7b57ab33da8412c78ba78 Mon Sep 17 00:00:00 2001 From: littlealex003 Date: Thu, 29 Apr 2021 07:30:00 +0200 Subject: [PATCH 1/2] Use random name for nickname if none set yet --- web-chat/package-lock.json | 11 +++++++++++ web-chat/package.json | 1 + web-chat/src/App.tsx | 3 ++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/web-chat/package-lock.json b/web-chat/package-lock.json index 1913c98eb8..6026934370 100644 --- a/web-chat/package-lock.json +++ b/web-chat/package-lock.json @@ -11,6 +11,7 @@ "peer-id": "^0.14.8", "react": "^17.0.2", "react-dom": "^17.0.2", + "server-name-generator": "^1.0.5", "waku": "file:../build/main/lib", "waku-chat": "file:../build/main/chat", "web-vitals": "^1.1.1" @@ -20600,6 +20601,11 @@ "node": ">= 0.8.0" } }, + "node_modules/server-name-generator": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/server-name-generator/-/server-name-generator-1.0.5.tgz", + "integrity": "sha512-LBo265lZl4rL/XETBhxPPssAzLNEl9fKNobJmFJxKcQQ43oONuHBQXR8evMnh9z2krWFVWmRPH7bWuvQvNQ4yw==" + }, "node_modules/set-blocking": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", @@ -41529,6 +41535,11 @@ "send": "0.17.1" } }, + "server-name-generator": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/server-name-generator/-/server-name-generator-1.0.5.tgz", + "integrity": "sha512-LBo265lZl4rL/XETBhxPPssAzLNEl9fKNobJmFJxKcQQ43oONuHBQXR8evMnh9z2krWFVWmRPH7bWuvQvNQ4yw==" + }, "set-blocking": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", diff --git a/web-chat/package.json b/web-chat/package.json index 5c1955cc1b..1740f60475 100644 --- a/web-chat/package.json +++ b/web-chat/package.json @@ -8,6 +8,7 @@ "peer-id": "^0.14.8", "react": "^17.0.2", "react-dom": "^17.0.2", + "server-name-generator": "^1.0.5", "waku": "file:../build/main/lib", "waku-chat": "file:../build/main/chat", "web-vitals": "^1.1.1" diff --git a/web-chat/src/App.tsx b/web-chat/src/App.tsx index 1907d2d819..a770c0458f 100644 --- a/web-chat/src/App.tsx +++ b/web-chat/src/App.tsx @@ -9,13 +9,14 @@ import handleCommand from './command'; import Room from './Room'; import Waku from 'waku/waku'; import { WakuContext } from './WakuContext'; +import { generate } from 'server-name-generator'; export const ChatContentTopic = 'dingpu'; export default function App() { let [stateMessages, setMessages] = useState([]); let [stateWaku, setWaku] = useState(undefined); - let [nick, setNick] = useState('web-chat'); + let [nick, setNick] = useState(generate()); useEffect(() => { const handleNewMessages = (event: { data: Uint8Array }) => { From 1016e85f70541c454a86d9fc3a71dd1eb053b2a4 Mon Sep 17 00:00:00 2001 From: Franck Royer Date: Thu, 29 Apr 2021 16:04:34 +1000 Subject: [PATCH 2/2] Enable pubsub topic filter in history queries Resolves #78 --- nim-waku | 2 +- proto/waku/v2/store.proto | 9 +++++---- src/lib/waku_store/history_rpc.ts | 5 ++++- src/lib/waku_store/index.ts | 14 +++++++++---- src/proto/waku/v2/store.ts | 33 ++++++++++++++++++++++++------- 5 files changed, 46 insertions(+), 17 deletions(-) diff --git a/nim-waku b/nim-waku index fb2ea06a4f..967db6d610 160000 --- a/nim-waku +++ b/nim-waku @@ -1 +1 @@ -Subproject commit fb2ea06a4fdfaee91aa081be2592eb79349ed6c2 +Subproject commit 967db6d6102646549bc2184b6fd26968ca764de7 diff --git a/proto/waku/v2/store.proto b/proto/waku/v2/store.proto index f3655274dd..aa8f03edd6 100644 --- a/proto/waku/v2/store.proto +++ b/proto/waku/v2/store.proto @@ -24,10 +24,11 @@ message ContentFilter { } message HistoryQuery { - repeated ContentFilter content_filters = 2; - optional PagingInfo paging_info = 3; - optional double start_time = 4; - optional double end_time = 5; + optional string pubsub_topic = 2; + repeated ContentFilter content_filters = 3; + optional PagingInfo paging_info = 4; + optional double start_time = 5; + optional double end_time = 6; } message HistoryResponse { diff --git a/src/lib/waku_store/history_rpc.ts b/src/lib/waku_store/history_rpc.ts index b94fb69914..8adb105616 100644 --- a/src/lib/waku_store/history_rpc.ts +++ b/src/lib/waku_store/history_rpc.ts @@ -3,13 +3,15 @@ import { v4 as uuid } from 'uuid'; import * as proto from '../../proto/waku/v2/store'; import { DEFAULT_CONTENT_TOPIC } from '../waku_message'; +import { RelayDefaultTopic } from '../waku_relay'; export class HistoryRPC { public constructor(public proto: proto.HistoryRPC) {} static createQuery( contentTopics: string[] = [DEFAULT_CONTENT_TOPIC], - cursor?: proto.Index + cursor?: proto.Index, + pubsubTopic: string = RelayDefaultTopic ): HistoryRPC { const pagingInfo = { pageSize: 10, @@ -24,6 +26,7 @@ export class HistoryRPC { return new HistoryRPC({ requestId: uuid(), query: { + pubsubTopic, contentFilters, pagingInfo, startTime: undefined, diff --git a/src/lib/waku_store/index.ts b/src/lib/waku_store/index.ts index b18cf6b387..0f68041803 100644 --- a/src/lib/waku_store/index.ts +++ b/src/lib/waku_store/index.ts @@ -8,7 +8,7 @@ import { WakuMessage } from '../waku_message'; import { HistoryRPC } from './history_rpc'; -export const StoreCodec = '/vac/waku/store/2.0.0-beta1'; +export const StoreCodec = '/vac/waku/store/2.0.0-beta3'; export class WakuStore { constructor(public libp2p: Libp2p) {} @@ -16,12 +16,14 @@ export class WakuStore { /** * Retrieve history from given peer * @param peerId - * @param topics + * @param contentTopics + * @param pubsubTopic * @throws if not able to reach peer */ async queryHistory( peerId: PeerId, - topics?: string[] + contentTopics?: string[], + pubsubTopic?: string ): Promise { const peer = this.libp2p.peerStore.get(peerId); if (!peer) throw 'Peer is unknown'; @@ -36,7 +38,11 @@ export class WakuStore { try { const { stream } = await connection.newStream(StoreCodec); try { - const historyRpcQuery = HistoryRPC.createQuery(topics, cursor); + const historyRpcQuery = HistoryRPC.createQuery( + contentTopics, + cursor, + pubsubTopic + ); const res = await pipe( [historyRpcQuery.encode()], lp.encode(), diff --git a/src/proto/waku/v2/store.ts b/src/proto/waku/v2/store.ts index 6c1ea8ced0..e575156192 100644 --- a/src/proto/waku/v2/store.ts +++ b/src/proto/waku/v2/store.ts @@ -57,6 +57,7 @@ export interface ContentFilter { } export interface HistoryQuery { + pubsubTopic?: string | undefined; contentFilters: ContentFilter[]; pagingInfo?: PagingInfo | undefined; startTime?: number | undefined; @@ -310,17 +311,20 @@ export const HistoryQuery = { message: HistoryQuery, writer: _m0.Writer = _m0.Writer.create() ): _m0.Writer { + if (message.pubsubTopic !== undefined) { + writer.uint32(18).string(message.pubsubTopic); + } for (const v of message.contentFilters) { - ContentFilter.encode(v!, writer.uint32(18).fork()).ldelim(); + ContentFilter.encode(v!, writer.uint32(26).fork()).ldelim(); } if (message.pagingInfo !== undefined) { - PagingInfo.encode(message.pagingInfo, writer.uint32(26).fork()).ldelim(); + PagingInfo.encode(message.pagingInfo, writer.uint32(34).fork()).ldelim(); } if (message.startTime !== undefined) { - writer.uint32(33).double(message.startTime); + writer.uint32(41).double(message.startTime); } if (message.endTime !== undefined) { - writer.uint32(41).double(message.endTime); + writer.uint32(49).double(message.endTime); } return writer; }, @@ -334,17 +338,20 @@ export const HistoryQuery = { const tag = reader.uint32(); switch (tag >>> 3) { case 2: + message.pubsubTopic = reader.string(); + break; + case 3: message.contentFilters.push( ContentFilter.decode(reader, reader.uint32()) ); break; - case 3: + case 4: message.pagingInfo = PagingInfo.decode(reader, reader.uint32()); break; - case 4: + case 5: message.startTime = reader.double(); break; - case 5: + case 6: message.endTime = reader.double(); break; default: @@ -358,6 +365,11 @@ export const HistoryQuery = { fromJSON(object: any): HistoryQuery { const message = { ...baseHistoryQuery } as HistoryQuery; message.contentFilters = []; + if (object.pubsubTopic !== undefined && object.pubsubTopic !== null) { + message.pubsubTopic = String(object.pubsubTopic); + } else { + message.pubsubTopic = undefined; + } if (object.contentFilters !== undefined && object.contentFilters !== null) { for (const e of object.contentFilters) { message.contentFilters.push(ContentFilter.fromJSON(e)); @@ -383,6 +395,8 @@ export const HistoryQuery = { toJSON(message: HistoryQuery): unknown { const obj: any = {}; + message.pubsubTopic !== undefined && + (obj.pubsubTopic = message.pubsubTopic); if (message.contentFilters) { obj.contentFilters = message.contentFilters.map((e) => e ? ContentFilter.toJSON(e) : undefined @@ -402,6 +416,11 @@ export const HistoryQuery = { fromPartial(object: DeepPartial): HistoryQuery { const message = { ...baseHistoryQuery } as HistoryQuery; message.contentFilters = []; + if (object.pubsubTopic !== undefined && object.pubsubTopic !== null) { + message.pubsubTopic = object.pubsubTopic; + } else { + message.pubsubTopic = undefined; + } if (object.contentFilters !== undefined && object.contentFilters !== null) { for (const e of object.contentFilters) { message.contentFilters.push(ContentFilter.fromPartial(e));