Skip to content

Commit

Permalink
chore: add rpc to persist data locally
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Trottier committed Dec 30, 2019
1 parent 851cfe0 commit 09d55c9
Show file tree
Hide file tree
Showing 11 changed files with 1,654 additions and 113 deletions.
68 changes: 68 additions & 0 deletions doc/PROTO.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@
- [P2PLsInfo](#pb.P2PLsInfo)
- [P2PRequest](#pb.P2PRequest)
- [P2PResponse](#pb.P2PResponse)
- [PersistRequest](#pb.PersistRequest)
- [PersistResponse](#pb.PersistResponse)
- [PersistResponse.ErrorsEntry](#pb.PersistResponse.ErrorsEntry)
- [PersistResponse.StatusEntry](#pb.PersistResponse.StatusEntry)

- [BSREQOPTS](#pb.BSREQOPTS)
- [BSREQTYPE](#pb.BSREQTYPE)
Expand Down Expand Up @@ -795,6 +799,69 @@ P2PResponse is a response message sent in response to a P2PRequest message




<a name="pb.PersistRequest"></a>

### PersistRequest



| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| cids | [string](#string) | repeated | cids to persist locally |






<a name="pb.PersistResponse"></a>

### PersistResponse



| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| status | [PersistResponse.StatusEntry](#pb.PersistResponse.StatusEntry) | repeated | key = cid, value = whether or not it was persisted |
| errors | [PersistResponse.ErrorsEntry](#pb.PersistResponse.ErrorsEntry) | repeated | key = cid, value = error if not persisted |






<a name="pb.PersistResponse.ErrorsEntry"></a>

### PersistResponse.ErrorsEntry



| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| key | [string](#string) | | |
| value | [string](#string) | | |






<a name="pb.PersistResponse.StatusEntry"></a>

### PersistResponse.StatusEntry



| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| key | [string](#string) | | |
| value | [bool](#bool) | | |








Expand Down Expand Up @@ -926,6 +993,7 @@ NodeAPI provide an API to control the underlying custom ipfs node
| Blockstore | [BlockstoreRequest](#pb.BlockstoreRequest) | [BlockstoreResponse](#pb.BlockstoreResponse) | Blockstore allows low-level management of the underlying blockstore |
| Dag | [DagRequest](#pb.DagRequest) | [DagResponse](#pb.DagResponse) | Dag is a unidirectional rpc allowing manipulation of low-level ipld objects |
| Keystore | [KeystoreRequest](#pb.KeystoreRequest) | [KeystoreResponse](#pb.KeystoreResponse) | Keystore is a unidirectional RPC allowing management of ipfs keystores |
| Persist | [PersistRequest](#pb.PersistRequest) | [PersistResponse](#pb.PersistResponse) | Persist is used to retrieve data from the network and make it available locally |



Expand Down
850 changes: 756 additions & 94 deletions go/node.pb.go

Large diffs are not rendered by default.

87 changes: 87 additions & 0 deletions java/pb/NodeAPIGrpc.java
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,38 @@ pb.Node.KeystoreResponse> getKeystoreMethod() {
return getKeystoreMethod;
}

private static volatile io.grpc.MethodDescriptor<pb.Node.PersistRequest,
pb.Node.PersistResponse> getPersistMethod;

@io.grpc.stub.annotations.RpcMethod(
fullMethodName = SERVICE_NAME + '/' + "Persist",
requestType = pb.Node.PersistRequest.class,
responseType = pb.Node.PersistResponse.class,
methodType = io.grpc.MethodDescriptor.MethodType.UNARY)
public static io.grpc.MethodDescriptor<pb.Node.PersistRequest,
pb.Node.PersistResponse> getPersistMethod() {
io.grpc.MethodDescriptor<pb.Node.PersistRequest, pb.Node.PersistResponse> getPersistMethod;
if ((getPersistMethod = NodeAPIGrpc.getPersistMethod) == null) {
synchronized (NodeAPIGrpc.class) {
if ((getPersistMethod = NodeAPIGrpc.getPersistMethod) == null) {
NodeAPIGrpc.getPersistMethod = getPersistMethod =
io.grpc.MethodDescriptor.<pb.Node.PersistRequest, pb.Node.PersistResponse>newBuilder()
.setType(io.grpc.MethodDescriptor.MethodType.UNARY)
.setFullMethodName(generateFullMethodName(
"pb.NodeAPI", "Persist"))
.setSampledToLocalTracing(true)
.setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
pb.Node.PersistRequest.getDefaultInstance()))
.setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
pb.Node.PersistResponse.getDefaultInstance()))
.setSchemaDescriptor(new NodeAPIMethodDescriptorSupplier("Persist"))
.build();
}
}
}
return getPersistMethod;
}

/**
* Creates a new async stub that supports all call types for the service
*/
Expand Down Expand Up @@ -314,6 +346,16 @@ public void keystore(pb.Node.KeystoreRequest request,
asyncUnimplementedUnaryCall(getKeystoreMethod(), responseObserver);
}

/**
* <pre>
* Persist is used to retrieve data from the network and make it available locally
* </pre>
*/
public void persist(pb.Node.PersistRequest request,
io.grpc.stub.StreamObserver<pb.Node.PersistResponse> responseObserver) {
asyncUnimplementedUnaryCall(getPersistMethod(), responseObserver);
}

@java.lang.Override public final io.grpc.ServerServiceDefinition bindService() {
return io.grpc.ServerServiceDefinition.builder(getServiceDescriptor())
.addMethod(
Expand Down Expand Up @@ -358,6 +400,13 @@ public void keystore(pb.Node.KeystoreRequest request,
pb.Node.KeystoreRequest,
pb.Node.KeystoreResponse>(
this, METHODID_KEYSTORE)))
.addMethod(
getPersistMethod(),
asyncUnaryCall(
new MethodHandlers<
pb.Node.PersistRequest,
pb.Node.PersistResponse>(
this, METHODID_PERSIST)))
.build();
}
}
Expand Down Expand Up @@ -450,6 +499,17 @@ public void keystore(pb.Node.KeystoreRequest request,
asyncUnaryCall(
getChannel().newCall(getKeystoreMethod(), getCallOptions()), request, responseObserver);
}

/**
* <pre>
* Persist is used to retrieve data from the network and make it available locally
* </pre>
*/
public void persist(pb.Node.PersistRequest request,
io.grpc.stub.StreamObserver<pb.Node.PersistResponse> responseObserver) {
asyncUnaryCall(
getChannel().newCall(getPersistMethod(), getCallOptions()), request, responseObserver);
}
}

/**
Expand Down Expand Up @@ -534,6 +594,16 @@ public pb.Node.KeystoreResponse keystore(pb.Node.KeystoreRequest request) {
return blockingUnaryCall(
getChannel(), getKeystoreMethod(), getCallOptions(), request);
}

/**
* <pre>
* Persist is used to retrieve data from the network and make it available locally
* </pre>
*/
public pb.Node.PersistResponse persist(pb.Node.PersistRequest request) {
return blockingUnaryCall(
getChannel(), getPersistMethod(), getCallOptions(), request);
}
}

/**
Expand Down Expand Up @@ -624,6 +694,17 @@ public com.google.common.util.concurrent.ListenableFuture<pb.Node.KeystoreRespon
return futureUnaryCall(
getChannel().newCall(getKeystoreMethod(), getCallOptions()), request);
}

/**
* <pre>
* Persist is used to retrieve data from the network and make it available locally
* </pre>
*/
public com.google.common.util.concurrent.ListenableFuture<pb.Node.PersistResponse> persist(
pb.Node.PersistRequest request) {
return futureUnaryCall(
getChannel().newCall(getPersistMethod(), getCallOptions()), request);
}
}

private static final int METHODID_CONN_MGMT = 0;
Expand All @@ -632,6 +713,7 @@ public com.google.common.util.concurrent.ListenableFuture<pb.Node.KeystoreRespon
private static final int METHODID_BLOCKSTORE = 3;
private static final int METHODID_DAG = 4;
private static final int METHODID_KEYSTORE = 5;
private static final int METHODID_PERSIST = 6;

private static final class MethodHandlers<Req, Resp> implements
io.grpc.stub.ServerCalls.UnaryMethod<Req, Resp>,
Expand Down Expand Up @@ -674,6 +756,10 @@ public void invoke(Req request, io.grpc.stub.StreamObserver<Resp> responseObserv
serviceImpl.keystore((pb.Node.KeystoreRequest) request,
(io.grpc.stub.StreamObserver<pb.Node.KeystoreResponse>) responseObserver);
break;
case METHODID_PERSIST:
serviceImpl.persist((pb.Node.PersistRequest) request,
(io.grpc.stub.StreamObserver<pb.Node.PersistResponse>) responseObserver);
break;
default:
throw new AssertionError();
}
Expand Down Expand Up @@ -741,6 +827,7 @@ public static io.grpc.ServiceDescriptor getServiceDescriptor() {
.addMethod(getBlockstoreMethod())
.addMethod(getDagMethod())
.addMethod(getKeystoreMethod())
.addMethod(getPersistMethod())
.build();
}
}
Expand Down
34 changes: 34 additions & 0 deletions js/node_grpc_pb.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,28 @@ function deserialize_pb_P2PResponse(buffer_arg) {
return node_pb.P2PResponse.deserializeBinary(new Uint8Array(buffer_arg));
}

function serialize_pb_PersistRequest(arg) {
if (!(arg instanceof node_pb.PersistRequest)) {
throw new Error('Expected argument of type pb.PersistRequest');
}
return Buffer.from(arg.serializeBinary());
}

function deserialize_pb_PersistRequest(buffer_arg) {
return node_pb.PersistRequest.deserializeBinary(new Uint8Array(buffer_arg));
}

function serialize_pb_PersistResponse(arg) {
if (!(arg instanceof node_pb.PersistResponse)) {
throw new Error('Expected argument of type pb.PersistResponse');
}
return Buffer.from(arg.serializeBinary());
}

function deserialize_pb_PersistResponse(buffer_arg) {
return node_pb.PersistResponse.deserializeBinary(new Uint8Array(buffer_arg));
}


// NodeAPI provide an API to control the underlying custom ipfs node
var NodeAPIService = exports.NodeAPIService = {
Expand Down Expand Up @@ -214,6 +236,18 @@ var NodeAPIService = exports.NodeAPIService = {
responseSerialize: serialize_pb_KeystoreResponse,
responseDeserialize: deserialize_pb_KeystoreResponse,
},
// Persist is used to retrieve data from the network and make it available locally
persist: {
path: '/pb.NodeAPI/Persist',
requestStream: false,
responseStream: false,
requestType: node_pb.PersistRequest,
responseType: node_pb.PersistResponse,
requestSerialize: serialize_pb_PersistRequest,
requestDeserialize: deserialize_pb_PersistRequest,
responseSerialize: serialize_pb_PersistResponse,
responseDeserialize: deserialize_pb_PersistResponse,
},
};

exports.NodeAPIClient = grpc.makeGenericClientConstructor(NodeAPIService);
Loading

0 comments on commit 09d55c9

Please sign in to comment.