Skip to content

Commit

Permalink
refactor: Rename remaining references to "recipient address" to "reci…
Browse files Browse the repository at this point in the history
…pient id" (#1205)
  • Loading branch information
gnarea authored Jan 31, 2023
1 parent 731b409 commit ee18d11
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 31 deletions.
6 changes: 3 additions & 3 deletions packages/daemon/src/parcelStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,15 +245,15 @@ async function getRelativeParcelKey(parcel: Parcel, direction: MessageDirection)

async function getRelativeParcelKeyFromParts(
senderId: string,
recipientAddress: string,
recipientId: string,
parcelId: string,
direction: MessageDirection,
): Promise<string> {
// Hash some components together to avoid exceeding Windows' 260-char limit for paths
const keyComponents =
direction === MessageDirection.TOWARDS_INTERNET
? [senderId, sha256Hex(recipientAddress + parcelId)]
: [recipientAddress, sha256Hex(senderId + parcelId)];
? [senderId, sha256Hex(recipientId + parcelId)]
: [recipientId, sha256Hex(senderId + parcelId)];
return join(...keyComponents);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,10 +347,10 @@ describe('streamCollectedParcelKeys', () => {
await sync;
});

function notifyParcelCollection(parcelKey: string, recipientAddress: string): void {
function notifyParcelCollection(parcelKey: string, recipientId: string): void {
const notification: ParcelCollectionNotification = {
parcelKey,
recipientId: recipientAddress,
recipientId,
type: 'parcelCollection',
};
const subprocess = getSubprocess();
Expand Down
6 changes: 2 additions & 4 deletions packages/daemon/src/sync/courierSync/CourierSyncManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ export class CourierSyncManager {
}
}

public async *streamCollectedParcelKeys(
recipientAddresses: readonly string[],
): AsyncIterable<string> {
public async *streamCollectedParcelKeys(recipientIds: readonly string[]): AsyncIterable<string> {
const collectionStream = new PassThrough({ objectMode: true });
const writeCollection = (collection: ParcelCollectionNotification) => {
collectionStream.write(collection);
Expand All @@ -55,7 +53,7 @@ export class CourierSyncManager {
messages: AsyncIterable<ParcelCollectionNotification>,
): AsyncIterable<string> {
for await (const message of messages) {
if (recipientAddresses.includes(message.recipientId)) {
if (recipientIds.includes(message.recipientId)) {
yield message.parcelKey;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ describe('streamStatus', () => {
setImmediate(() => {
emitValidSubprocessMessage({
parcelKey: 'key',
recipientAddress: 'recipient',
recipientId: 'recipient',
type: 'parcelCollection',
});
emitValidSubprocessMessage({ type: 'status', status: 'connected' });
Expand Down Expand Up @@ -200,7 +200,7 @@ describe('watchCollectionsForRecipients', () => {
await manager.start();
const status: ParcelCollectionNotification = {
parcelKey: PARCEL_KEY,
recipientAddress: RECIPIENT_ADDRESS,
recipientId: RECIPIENT_ADDRESS,
type: 'parcelCollection',
};
emitValidSubprocessMessage(status);
Expand All @@ -220,7 +220,7 @@ describe('watchCollectionsForRecipients', () => {
setImmediate(async () => {
emitValidSubprocessMessage({
parcelKey: PARCEL_KEY,
recipientAddress: RECIPIENT_ADDRESS,
recipientId: RECIPIENT_ADDRESS,
type: 'parcelCollection',
});
});
Expand All @@ -241,12 +241,12 @@ describe('watchCollectionsForRecipients', () => {
setImmediate(async () => {
emitValidSubprocessMessage({
parcelKey: PARCEL_KEY,
recipientAddress: RECIPIENT_ADDRESS,
recipientId: RECIPIENT_ADDRESS,
type: 'parcelCollection',
});
emitValidSubprocessMessage({
parcelKey: parcel2Key,
recipientAddress: recipient2Address,
recipientId: recipient2Address,
type: 'parcelCollection',
});
});
Expand All @@ -265,12 +265,12 @@ describe('watchCollectionsForRecipients', () => {
setImmediate(async () => {
emitValidSubprocessMessage({
parcelKey: 'the parcel key',
recipientAddress: 'invalid recipient',
recipientId: 'invalid recipient',
type: 'parcelCollection',
});
emitValidSubprocessMessage({
parcelKey: PARCEL_KEY,
recipientAddress: RECIPIENT_ADDRESS,
recipientId: RECIPIENT_ADDRESS,
type: 'parcelCollection',
});
});
Expand All @@ -290,7 +290,7 @@ describe('watchCollectionsForRecipients', () => {
getSubprocess().write({ foo: 'bar' });
emitValidSubprocessMessage({
parcelKey: PARCEL_KEY,
recipientAddress: RECIPIENT_ADDRESS,
recipientId: RECIPIENT_ADDRESS,
type: 'parcelCollection',
});
});
Expand All @@ -310,7 +310,7 @@ describe('watchCollectionsForRecipients', () => {
emitValidSubprocessMessage({ type: 'status', status: 'connected' });
emitValidSubprocessMessage({
parcelKey: PARCEL_KEY,
recipientAddress: RECIPIENT_ADDRESS,
recipientId: RECIPIENT_ADDRESS,
type: 'parcelCollection',
});
});
Expand All @@ -329,7 +329,7 @@ describe('watchCollectionsForRecipients', () => {
setImmediate(() => {
emitValidSubprocessMessage({
parcelKey: PARCEL_KEY,
recipientAddress: RECIPIENT_ADDRESS,
recipientId: RECIPIENT_ADDRESS,
type: 'parcelCollection',
});
});
Expand All @@ -355,13 +355,13 @@ describe('watchCollectionsForRecipients', () => {
setImmediate(async () => {
subprocess1.write({
parcelKey: PARCEL_KEY,
recipientAddress: RECIPIENT_ADDRESS,
recipientId: RECIPIENT_ADDRESS,
type: 'parcelCollection',
});
await manager.restart();
subprocess2.write({
parcelKey: parcel2Key,
recipientAddress: RECIPIENT_ADDRESS,
recipientId: RECIPIENT_ADDRESS,
type: 'parcelCollection',
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,13 @@ export class ParcelCollectorManager {
}

public async *watchCollectionsForRecipients(
recipientAddresses: readonly string[],
recipientIds: readonly string[],
): AsyncIterable<string> {
yield* await pipe(
this.streamMessages(),
async function* (messages: AsyncIterable<ParcelCollectorMessage>): AsyncIterable<string> {
for await (const message of messages) {
if (
message.type === 'parcelCollection' &&
recipientAddresses.includes(message.recipientAddress)
) {
if (message.type === 'parcelCollection' && recipientIds.includes(message.recipientId)) {
yield message.parcelKey;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { IPCMessage } from '../../ipc';

export interface ParcelCollectionNotification extends IPCMessage {
readonly parcelKey: string;
readonly recipientAddress: string;
readonly recipientId: string;
readonly type: 'parcelCollection';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ describe('Parcel collection', () => {
parcel: expect.objectContaining({
id: parcel.id,
key: parcelKey,
recipientAddress: parcel.recipient.id,
recipientId: parcel.recipient.id,
}),
}),
);
Expand All @@ -201,7 +201,7 @@ describe('Parcel collection', () => {
expect(mockParcelStore).toBeCalled();
expect(getParentMessages()).toContainEqual<ParcelCollectionNotification>({
parcelKey,
recipientAddress: parcel.recipient.id,
recipientId: parcel.recipient.id,
type: 'parcelCollection',
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,13 @@ function processParcels(
if (parcelKey) {
const collectionMessage: ParcelCollectionNotification = {
parcelKey,
recipientAddress: parcel.recipient.id,
recipientId: parcel.recipient.id,
type: 'parcelCollection',
};
parentStream.write(collectionMessage);
}
logger.info(
{ parcel: { id: parcel.id, key: parcelKey, recipientAddress: parcel.recipient.id } },
{ parcel: { id: parcel.id, key: parcelKey, recipientId: parcel.recipient.id } },
'Saved new parcel',
);
}
Expand Down

0 comments on commit ee18d11

Please sign in to comment.