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

Add mcclient manifest lookup command #175

Merged
merged 2 commits into from
Jan 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/client/api/RestClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,12 @@ class RestClient {
.then(parseBoolResponse)
}

listManifestsForEntity (entityId: string): Promise<Array<Object>> {
return this.getRequest(`dir/listmf/${entityId}`)
.then(r => new NDJsonResponse(r))
.then(r => r.values())
}

shutdown (): Promise<boolean> {
return this.postRequest('shutdown', '', false)
.then(() => true)
Expand Down
21 changes: 21 additions & 0 deletions src/client/cli/commands/manifest/lookup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// @flow

const RestClient = require('../../../api/RestClient')
const { subcommand, printJSON } = require('../../util')

module.exports = {
command: 'lookup <entityId>',
builder: {
entityId: {
type: 'string',
description: 'An "entity" identifier that can be used to verify a public identity. ' +
'e.g: "blockstack:mediachainlabs.id" or "keybase:yusef"'
}
},
description: `Query the directory for the manifests belonging to \`entityId\`.\n`,
handler: subcommand((opts: {client: RestClient, entityId: string}) => {
const {client, entityId} = opts
return client.listManifestsForEntity(entityId)
.then(m => printJSON(m))
})
}
13 changes: 13 additions & 0 deletions src/protobuf/dir.proto
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
syntax = "proto3";
package proto;

import "manifest.proto";

message PeerInfo {
string id = 1; // peer id
repeated bytes addr = 2; // peer multiaddrs
Expand All @@ -15,6 +17,7 @@ message PublisherInfo {
message RegisterPeer {
PeerInfo info = 1;
PublisherInfo publisher = 2; // optional (v1.4)
repeated Manifest manifest = 3; // optional (v1.5)
}

// /mediachain/dir/lookup
Expand All @@ -41,3 +44,13 @@ message ListNamespacesRequest {}
message ListNamespacesResponse {
repeated string namespaces = 1;
}

// /mediachain/dir/listmf
message ListManifestRequest {
string entity = 1;
}

message ListManifestResponse {
repeated Manifest manifest = 1;
}

16 changes: 14 additions & 2 deletions src/protobuf/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import type {
LookupPeerResponseMsg,
ListPeersRequestMsg,
ListPeersResponseMsg,
ListManifestRequestMsg,
ListManifestResponseMsg,
ManifestRequestMsg,
ManifestResponseMsg,
PingMsg,
PongMsg,
NodeInfoRequestMsg,
Expand Down Expand Up @@ -53,11 +57,15 @@ type AllProtos = {
LookupPeerRequest: ProtoCodec<LookupPeerRequestMsg>,
LookupPeerResponse: ProtoCodec<LookupPeerResponseMsg>,
ListPeersRequest: ProtoCodec<ListPeersRequestMsg>,
ListPeersResponse: ProtoCodec<ListPeersResponseMsg>
ListPeersResponse: ProtoCodec<ListPeersResponseMsg>,
ListManifestRequest: ProtoCodec<ListManifestRequestMsg>,
ListManifestResponse: ProtoCodec<ListManifestResponseMsg>
},
node: {
Ping: ProtoCodec<PingMsg>,
Pong: ProtoCodec<PongMsg>,
ManifestRequest: ProtoCodec<ManifestRequestMsg>,
ManifestResponse: ProtoCodec<ManifestResponseMsg>,
NodeInfoRequest: ProtoCodec<NodeInfoRequestMsg>,
NodeInfo: ProtoCodec<NodeInfoMsg>,
QueryRequest: ProtoCodec<QueryRequestMsg>,
Expand Down Expand Up @@ -120,11 +128,15 @@ function loadProtos (): AllProtos {
LookupPeerRequest: pb.LookupPeerRequest,
LookupPeerResponse: pb.LookupPeerResponse,
ListPeersRequest: pb.ListPeersRequest,
ListPeersResponse: pb.ListPeersResponse
ListPeersResponse: pb.ListPeersResponse,
ListManifestRequest: pb.ListManifestRequest,
ListManifestResponse: pb.ListManifestResponse
},
node: {
Ping: pb.Ping,
Pong: pb.Pong,
ManifestRequest: pb.ManifestRequest,
ManifestResponse: pb.ManifestResponse,
NodeInfoRequest: pb.NodeInfoRequest,
NodeInfo: pb.NodeInfo,
QueryRequest: pb.QueryRequest,
Expand Down
8 changes: 8 additions & 0 deletions src/protobuf/node.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ syntax = "proto3";
package proto;

import "stmt.proto";
import "manifest.proto";

// end of result stream marker
message StreamEnd {}
Expand All @@ -20,6 +21,13 @@ message NodeInfo {
string info = 3;
}

// /mediachain/node/manifest
message ManifestRequest {}

message ManifestResponse {
repeated Manifest manifest = 1;
}

// /mediachain/node/ping
message Ping {}
message Pong {}
Expand Down
17 changes: 16 additions & 1 deletion src/protobuf/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export type PublisherInfoMsg = {

export type RegisterPeerMsg = {
info: PeerInfoMsg,
publisher?: PublisherInfoMsg
publisher?: PublisherInfoMsg,
manifest?: Array<ManifestMsg>
}

export type LookupPeerRequestMsg = {
Expand All @@ -33,8 +34,22 @@ export type ListPeersResponseMsg = {
peers: Array<string>
}

export type ListManifestRequestMsg = {
entity: string
}

export type ListManifestResponseMsg = {
manifest: Array<ManifestMsg>
}

// node.proto

export type ManifestRequestMsg = {}

export type ManifestResponseMsg = {
manifest: Array<ManifestMsg>
}

export type PingMsg = { }
export type PongMsg = { }

Expand Down