Skip to content

Commit

Permalink
Rename message types
Browse files Browse the repository at this point in the history
  • Loading branch information
haadcode committed Nov 29, 2024
1 parent 435d280 commit 376fd85
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ Send one of the following messages to the protocol in order to communicate with
#### Adding a DB for replication

```
type: PIN_ADD
type: 1 ("ADD")
id: The id of the requester
signature: One or more database addresses signed by the requester
addresses: One or more database addresses to add to the storage
Expand All @@ -231,7 +231,7 @@ If successful, an OK response will be sent. If it fails, an error will be return
#### Removing a DB for replication

```
type: PIN_REMOVE
type: 2 ("REMOVE")
id: The id of the requester
signature: One or more database addresses signed by the requester
addresses: One or more database addresses to remove from the storage
Expand Down
4 changes: 2 additions & 2 deletions src/lib/handle-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ export const handleRequest = (orbiter) => source => {
}

switch (type) {
case Requests.PIN_ADD: {
case Requests.ADD: {
await handleAddRequest({ orbitdb, databases, id, addresses })
response = ResponseMessage(Responses.OK)
break
}
case Requests.PIN_REMOVE: {
case Requests.REMOVE: {
await handleRemoveRequest({ orbitdb, databases, id, addresses })
response = ResponseMessage(Responses.OK)
break
Expand Down
4 changes: 2 additions & 2 deletions src/lib/lander.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ export default async ({ orbitdb, orbiterAddressOrId }) => {
}

const add = async (addresses) => {
const addDBs = () => [request(Requests.PIN_ADD, toArray(addresses))]
const addDBs = () => [request(Requests.ADD, toArray(addresses))]
const stream = await orbitdb.ipfs.libp2p.dialProtocol(orbiterAddressOrId, voyagerProtocol, { runOnLimitedConnection: true })
const added = await pipe(addDBs, stream, parseResponse)
return added
}

const remove = async (addresses) => {
const removeDBs = () => [request(Requests.PIN_REMOVE, toArray(addresses))]
const removeDBs = () => [request(Requests.REMOVE, toArray(addresses))]
const stream = await orbitdb.ipfs.libp2p.dialProtocol(orbiterAddressOrId, voyagerProtocol, { runOnLimitedConnection: true })
const removed = await pipe(removeDBs, stream, parseResponse)
return removed
Expand Down
4 changes: 2 additions & 2 deletions src/lib/messages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'

export const Requests = Object.freeze({
PIN_ADD: 1,
PIN_REMOVE: 2
ADD: 1,
REMOVE: 2
})

export const Responses = Object.freeze({
Expand Down
2 changes: 1 addition & 1 deletion test/messages.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('Messages', function () {
const addDBs = ({ type, signer } = {}) => source => {
return (async function * () {
const addresses = [db.address]
const message = await RequestMessage(type || Requests.PIN_ADD, addresses, lander.orbitdb.identity, signer)
const message = await RequestMessage(type || Requests.ADD, addresses, lander.orbitdb.identity, signer)
yield message
})()
}
Expand Down

0 comments on commit 376fd85

Please sign in to comment.