diff --git a/docker/dev.Dockerfile b/docker/dev.Dockerfile index 8e65a7e..b62e3ce 100644 --- a/docker/dev.Dockerfile +++ b/docker/dev.Dockerfile @@ -5,4 +5,4 @@ RUN apk add git python3 make RUN go get -d -v . RUN make deps -CMD ["sh"] \ No newline at end of file +CMD ["sh"] diff --git a/main.go b/main.go index e34f2f1..eaca5ff 100644 --- a/main.go +++ b/main.go @@ -27,14 +27,15 @@ import ( ) type ShardIDType = int64 +type PBInt = int64 const numShards ShardIDType = 100 -func makeKey(seed int64) (ic.PrivKey, peer.ID, error) { +func makeKey(seed int) (ic.PrivKey, peer.ID, error) { // If the seed is zero, use real cryptographic randomness. Otherwise, use a // deterministic randomness source to make generated keys stay the same // across multiple runs - r := mrand.New(mrand.NewSource(seed)) + r := mrand.New(mrand.NewSource(int64(seed))) // r := rand.Reader // Generate a key pair for this host. We will use it at least @@ -57,7 +58,7 @@ func makeKey(seed int64) (ic.PrivKey, peer.ID, error) { func makeNode( ctx context.Context, listenPort int, - randseed int64, + randseed int, doBootstrapping bool, bootstrapPeers []pstore.PeerInfo) (*Node, error) { // FIXME: should be set to localhost if we don't want to expose it to outside @@ -117,7 +118,7 @@ func main() { // Parse options from the command line - seed := flag.Int64("seed", 0, "set random seed for id generation") + seed := flag.Int("seed", 0, "set random seed for id generation") listenPort := flag.Int( "port", defaultListenPort, @@ -146,7 +147,7 @@ func main() { func runServer( listenPort int, - seed int64, + seed int, doBootstrapping bool, bootnodes []pstore.PeerInfo, rpcAddr string) { @@ -178,7 +179,7 @@ func runClient(rpcAddr string, cliArgs []string) { } targetIP := rpcArgs[0] targetPort, err := strconv.Atoi(rpcArgs[1]) - targetSeed, err := strconv.ParseInt(rpcArgs[2], 10, 64) + targetSeed, err := strconv.Atoi(rpcArgs[2]) if err != nil { panic(err) } diff --git a/main_test.go b/main_test.go index 5ae76a8..f8c3e26 100644 --- a/main_test.go +++ b/main_test.go @@ -12,6 +12,8 @@ import ( // gologging "github.com/whyrusleeping/go-logging" ) +var nodeCount int + func makeUnbootstrappedNode(t *testing.T, ctx context.Context, number int) *Node { return makeTestingNode(t, ctx, number, false, nil) } @@ -22,8 +24,12 @@ func makeTestingNode( number int, doBootstrapping bool, bootstrapPeers []pstore.PeerInfo) *Node { - listeningPort := number + 10000 - node, err := makeNode(ctx, listeningPort, int64(number), doBootstrapping, bootstrapPeers) + // FIXME: + // 1. Use 20000 to avoid conflitcs with the running nodes in the environment + // 2. Avoid reuse of listeningPort in the entire test, to avoid `dial error`s + listeningPort := 20000 + nodeCount + nodeCount++ + node, err := makeNode(ctx, listeningPort, number, doBootstrapping, bootstrapPeers) if err != nil { t.Error("Failed to create node") } @@ -253,12 +259,12 @@ func TestRequestCollation(t *testing.T) { defer cancel() node0, node1 := makePeerNodes(t, ctx) shardID := ShardIDType(1) - period := int64(42) + period := 42 collation, err := node0.requestCollation(ctx, node1.ID(), shardID, period, "2") if err != nil { t.Error("request collation failed") } - if collation.ShardID != shardID || collation.Period != period { + if collation.ShardID != shardID || collation.Period != PBInt(period) { t.Errorf( "responded collation does not correspond to the request: collation.ShardID=%v, request.shardID=%v, collation.Period=%v, request.period=%v", collation.ShardID, diff --git a/node.go b/node.go index 1e7649d..a6dc9e9 100644 --- a/node.go +++ b/node.go @@ -10,7 +10,7 @@ import ( ) // node client version -const clientVersion = "go-p2p-node/0.0.1" +const clientVersion = "sharding-p2p-node/0.0.1" // Node type - a p2p host implementing one or more p2p protocols type Node struct { diff --git a/pb/rpc/rpc.pb.go b/pb/rpc/rpc.pb.go index 2e27b59..287dabc 100644 --- a/pb/rpc/rpc.pb.go +++ b/pb/rpc/rpc.pb.go @@ -26,7 +26,7 @@ const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package // AddPeer type RPCAddPeerReq struct { Ip string `protobuf:"bytes,1,opt,name=ip,proto3" json:"ip,omitempty"` - Port int32 `protobuf:"varint,2,opt,name=port,proto3" json:"port,omitempty"` + Port int64 `protobuf:"varint,2,opt,name=port,proto3" json:"port,omitempty"` Seed int64 `protobuf:"varint,3,opt,name=seed,proto3" json:"seed,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` @@ -37,7 +37,7 @@ func (m *RPCAddPeerReq) Reset() { *m = RPCAddPeerReq{} } func (m *RPCAddPeerReq) String() string { return proto.CompactTextString(m) } func (*RPCAddPeerReq) ProtoMessage() {} func (*RPCAddPeerReq) Descriptor() ([]byte, []int) { - return fileDescriptor_rpc_71a1ae02a48c7975, []int{0} + return fileDescriptor_rpc_5bc1ae5500c393c6, []int{0} } func (m *RPCAddPeerReq) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_RPCAddPeerReq.Unmarshal(m, b) @@ -64,7 +64,7 @@ func (m *RPCAddPeerReq) GetIp() string { return "" } -func (m *RPCAddPeerReq) GetPort() int32 { +func (m *RPCAddPeerReq) GetPort() int64 { if m != nil { return m.Port } @@ -90,7 +90,7 @@ func (m *RPCSubscribeShardReq) Reset() { *m = RPCSubscribeShardReq{} } func (m *RPCSubscribeShardReq) String() string { return proto.CompactTextString(m) } func (*RPCSubscribeShardReq) ProtoMessage() {} func (*RPCSubscribeShardReq) Descriptor() ([]byte, []int) { - return fileDescriptor_rpc_71a1ae02a48c7975, []int{1} + return fileDescriptor_rpc_5bc1ae5500c393c6, []int{1} } func (m *RPCSubscribeShardReq) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_RPCSubscribeShardReq.Unmarshal(m, b) @@ -129,7 +129,7 @@ func (m *RPCUnsubscribeShardReq) Reset() { *m = RPCUnsubscribeShardReq{} func (m *RPCUnsubscribeShardReq) String() string { return proto.CompactTextString(m) } func (*RPCUnsubscribeShardReq) ProtoMessage() {} func (*RPCUnsubscribeShardReq) Descriptor() ([]byte, []int) { - return fileDescriptor_rpc_71a1ae02a48c7975, []int{2} + return fileDescriptor_rpc_5bc1ae5500c393c6, []int{2} } func (m *RPCUnsubscribeShardReq) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_RPCUnsubscribeShardReq.Unmarshal(m, b) @@ -167,7 +167,7 @@ func (m *RPCGetSubscribedShardReq) Reset() { *m = RPCGetSubscribedShardR func (m *RPCGetSubscribedShardReq) String() string { return proto.CompactTextString(m) } func (*RPCGetSubscribedShardReq) ProtoMessage() {} func (*RPCGetSubscribedShardReq) Descriptor() ([]byte, []int) { - return fileDescriptor_rpc_71a1ae02a48c7975, []int{3} + return fileDescriptor_rpc_5bc1ae5500c393c6, []int{3} } func (m *RPCGetSubscribedShardReq) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_RPCGetSubscribedShardReq.Unmarshal(m, b) @@ -199,7 +199,7 @@ func (m *RPCGetSubscribedShardReply) Reset() { *m = RPCGetSubscribedShar func (m *RPCGetSubscribedShardReply) String() string { return proto.CompactTextString(m) } func (*RPCGetSubscribedShardReply) ProtoMessage() {} func (*RPCGetSubscribedShardReply) Descriptor() ([]byte, []int) { - return fileDescriptor_rpc_71a1ae02a48c7975, []int{4} + return fileDescriptor_rpc_5bc1ae5500c393c6, []int{4} } func (m *RPCGetSubscribedShardReply) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_RPCGetSubscribedShardReply.Unmarshal(m, b) @@ -236,9 +236,9 @@ func (m *RPCGetSubscribedShardReply) GetStatus() bool { // BroadcastCollation type RPCBroadcastCollationReq struct { ShardID int64 `protobuf:"varint,1,opt,name=shardID,proto3" json:"shardID,omitempty"` - Number int32 `protobuf:"varint,2,opt,name=number,proto3" json:"number,omitempty"` - Size int32 `protobuf:"varint,3,opt,name=size,proto3" json:"size,omitempty"` - Period int32 `protobuf:"varint,4,opt,name=period,proto3" json:"period,omitempty"` + Number int64 `protobuf:"varint,2,opt,name=number,proto3" json:"number,omitempty"` + Size int64 `protobuf:"varint,3,opt,name=size,proto3" json:"size,omitempty"` + Period int64 `protobuf:"varint,4,opt,name=period,proto3" json:"period,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -248,7 +248,7 @@ func (m *RPCBroadcastCollationReq) Reset() { *m = RPCBroadcastCollationR func (m *RPCBroadcastCollationReq) String() string { return proto.CompactTextString(m) } func (*RPCBroadcastCollationReq) ProtoMessage() {} func (*RPCBroadcastCollationReq) Descriptor() ([]byte, []int) { - return fileDescriptor_rpc_71a1ae02a48c7975, []int{5} + return fileDescriptor_rpc_5bc1ae5500c393c6, []int{5} } func (m *RPCBroadcastCollationReq) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_RPCBroadcastCollationReq.Unmarshal(m, b) @@ -275,21 +275,68 @@ func (m *RPCBroadcastCollationReq) GetShardID() int64 { return 0 } -func (m *RPCBroadcastCollationReq) GetNumber() int32 { +func (m *RPCBroadcastCollationReq) GetNumber() int64 { if m != nil { return m.Number } return 0 } -func (m *RPCBroadcastCollationReq) GetSize() int32 { +func (m *RPCBroadcastCollationReq) GetSize() int64 { if m != nil { return m.Size } return 0 } -func (m *RPCBroadcastCollationReq) GetPeriod() int32 { +func (m *RPCBroadcastCollationReq) GetPeriod() int64 { + if m != nil { + return m.Period + } + return 0 +} + +// RequestCollation +type RPCRequestCollationReq struct { + ShardID int64 `protobuf:"varint,1,opt,name=shardID,proto3" json:"shardID,omitempty"` + Period int64 `protobuf:"varint,4,opt,name=period,proto3" json:"period,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *RPCRequestCollationReq) Reset() { *m = RPCRequestCollationReq{} } +func (m *RPCRequestCollationReq) String() string { return proto.CompactTextString(m) } +func (*RPCRequestCollationReq) ProtoMessage() {} +func (*RPCRequestCollationReq) Descriptor() ([]byte, []int) { + return fileDescriptor_rpc_5bc1ae5500c393c6, []int{6} +} +func (m *RPCRequestCollationReq) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_RPCRequestCollationReq.Unmarshal(m, b) +} +func (m *RPCRequestCollationReq) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_RPCRequestCollationReq.Marshal(b, m, deterministic) +} +func (dst *RPCRequestCollationReq) XXX_Merge(src proto.Message) { + xxx_messageInfo_RPCRequestCollationReq.Merge(dst, src) +} +func (m *RPCRequestCollationReq) XXX_Size() int { + return xxx_messageInfo_RPCRequestCollationReq.Size(m) +} +func (m *RPCRequestCollationReq) XXX_DiscardUnknown() { + xxx_messageInfo_RPCRequestCollationReq.DiscardUnknown(m) +} + +var xxx_messageInfo_RPCRequestCollationReq proto.InternalMessageInfo + +func (m *RPCRequestCollationReq) GetShardID() int64 { + if m != nil { + return m.ShardID + } + return 0 +} + +func (m *RPCRequestCollationReq) GetPeriod() int64 { if m != nil { return m.Period } @@ -307,7 +354,7 @@ func (m *RPCStopServerReq) Reset() { *m = RPCStopServerReq{} } func (m *RPCStopServerReq) String() string { return proto.CompactTextString(m) } func (*RPCStopServerReq) ProtoMessage() {} func (*RPCStopServerReq) Descriptor() ([]byte, []int) { - return fileDescriptor_rpc_71a1ae02a48c7975, []int{6} + return fileDescriptor_rpc_5bc1ae5500c393c6, []int{7} } func (m *RPCStopServerReq) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_RPCStopServerReq.Unmarshal(m, b) @@ -339,7 +386,7 @@ func (m *RPCReply) Reset() { *m = RPCReply{} } func (m *RPCReply) String() string { return proto.CompactTextString(m) } func (*RPCReply) ProtoMessage() {} func (*RPCReply) Descriptor() ([]byte, []int) { - return fileDescriptor_rpc_71a1ae02a48c7975, []int{7} + return fileDescriptor_rpc_5bc1ae5500c393c6, []int{8} } func (m *RPCReply) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_RPCReply.Unmarshal(m, b) @@ -380,6 +427,7 @@ func init() { proto.RegisterType((*RPCGetSubscribedShardReq)(nil), "proto.rpc.RPCGetSubscribedShardReq") proto.RegisterType((*RPCGetSubscribedShardReply)(nil), "proto.rpc.RPCGetSubscribedShardReply") proto.RegisterType((*RPCBroadcastCollationReq)(nil), "proto.rpc.RPCBroadcastCollationReq") + proto.RegisterType((*RPCRequestCollationReq)(nil), "proto.rpc.RPCRequestCollationReq") proto.RegisterType((*RPCStopServerReq)(nil), "proto.rpc.RPCStopServerReq") proto.RegisterType((*RPCReply)(nil), "proto.rpc.RPCReply") } @@ -623,34 +671,34 @@ var _Poc_serviceDesc = grpc.ServiceDesc{ Metadata: "rpc.proto", } -func init() { proto.RegisterFile("rpc.proto", fileDescriptor_rpc_71a1ae02a48c7975) } - -var fileDescriptor_rpc_71a1ae02a48c7975 = []byte{ - // 402 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x52, 0x4d, 0x4f, 0xe3, 0x30, - 0x10, 0xdd, 0x34, 0xfd, 0x1c, 0x69, 0xab, 0xca, 0xbb, 0xaa, 0xac, 0xec, 0x61, 0x83, 0x11, 0x52, - 0x4e, 0x39, 0x14, 0x4e, 0x88, 0x03, 0x10, 0xa4, 0x82, 0xc4, 0xc1, 0x72, 0xc5, 0x0f, 0xc8, 0x87, - 0x05, 0x91, 0xda, 0xda, 0xd8, 0x2e, 0x02, 0xfe, 0x25, 0xff, 0x08, 0xc5, 0x49, 0x0b, 0x69, 0x1b, - 0x10, 0xa7, 0xcc, 0xc4, 0xcf, 0x6f, 0x3c, 0xef, 0x3d, 0x18, 0x28, 0x99, 0x86, 0x52, 0x09, 0x23, - 0xd0, 0xc0, 0x7e, 0x42, 0x25, 0x53, 0x32, 0x85, 0xdf, 0x8c, 0x46, 0x17, 0x59, 0x46, 0x39, 0x57, - 0x8c, 0x3f, 0xa2, 0x21, 0xb4, 0x72, 0x89, 0x1d, 0xdf, 0x09, 0x06, 0xac, 0x95, 0x4b, 0x84, 0xa0, - 0x2d, 0x85, 0x32, 0xb8, 0xe5, 0x3b, 0x41, 0x87, 0xd9, 0xba, 0xf8, 0xa7, 0x39, 0xcf, 0xb0, 0xeb, - 0x3b, 0x81, 0xcb, 0x6c, 0x4d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, 0x33, 0xc9, 0x2f, 0x74, - 0x0d, 0xc3, 0xba, 0xc9, 0xe8, 0x7f, 0x1d, 0xb8, 0x13, 0x81, 0x26, 0xa6, 0x5b, 0x18, 0x6d, 0x5b, - 0x8f, 0x0e, 0xea, 0xd0, 0x3d, 0xd1, 0x68, 0x62, 0x4b, 0x00, 0xed, 0xda, 0x8e, 0x0e, 0xeb, 0xe0, - 0xbd, 0xa1, 0xf1, 0x8e, 0xbe, 0x07, 0x95, 0x33, 0x28, 0xa0, 0xdd, 0x20, 0x6c, 0xcf, 0xd8, 0x1b, - 0x95, 0xa6, 0x57, 0x9f, 0x03, 0x7c, 0x18, 0x8c, 0xfe, 0x6d, 0x29, 0xf9, 0xd9, 0xfa, 0x06, 0x86, - 0xa4, 0x6b, 0xff, 0x1e, 0xbf, 0x07, 0x00, 0x00, 0xff, 0xff, 0x34, 0x64, 0xc8, 0xe5, 0xdf, 0x03, - 0x00, 0x00, +func init() { proto.RegisterFile("rpc.proto", fileDescriptor_rpc_5bc1ae5500c393c6) } + +var fileDescriptor_rpc_5bc1ae5500c393c6 = []byte{ + // 410 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x52, 0xcd, 0x8e, 0xd3, 0x30, + 0x18, 0x24, 0xcd, 0x6a, 0xdb, 0x7e, 0x12, 0xab, 0xca, 0xa0, 0xca, 0x0a, 0x07, 0x8a, 0x11, 0x52, + 0x4f, 0x39, 0x14, 0x4e, 0x88, 0x03, 0x10, 0xa4, 0x02, 0xe2, 0x60, 0xb9, 0xe2, 0x01, 0xf2, 0xf3, + 0x09, 0x22, 0xb5, 0xb5, 0x6b, 0x3b, 0x08, 0xfa, 0x96, 0xbc, 0x11, 0xb2, 0x93, 0x06, 0xd2, 0x26, + 0xac, 0x7a, 0x8a, 0xc7, 0x1e, 0xcf, 0x38, 0xf3, 0x0d, 0x4c, 0xb5, 0xca, 0x63, 0xa5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f, 0x7d, 0x3a, 0x02, 0x0f, 0x15, 0x5e, 0xe3, 0xdb, 0xab, 0x45, 0x60, 0xe6, + 0xa6, 0x63, 0xa5, 0xda, 0xa0, 0xfe, 0xe1, 0x27, 0xcd, 0xde, 0xc0, 0xc4, 0xeb, 0xbb, 0x64, 0x28, + 0x8c, 0x77, 0x68, 0x4c, 0xfa, 0x0d, 0x9b, 0xd1, 0x9f, 0xe0, 0x50, 0x2e, 0xab, 0xdf, 0x21, 0x84, + 0x5c, 0xe6, 0xe4, 0x35, 0x8c, 0x9b, 0xf6, 0x10, 0x1a, 0xb7, 0xbd, 0x8a, 0x3b, 0xa5, 0x8a, 0x1e, + 0x75, 0x4f, 0xbc, 0x27, 0x7b, 0x40, 0x3e, 0xc2, 0x5d, 0xb7, 0x30, 0xe4, 0x69, 0x97, 0x78, 0x51, + 0xa7, 0x21, 0xa5, 0x2f, 0x30, 0x3b, 0xaf, 0x11, 0x79, 0xd6, 0xa5, 0xf6, 0xd4, 0x6c, 0x48, 0x2d, + 0x03, 0x72, 0x59, 0x21, 0xf2, 0xbc, 0x4b, 0xee, 0x2d, 0x60, 0xf4, 0xe2, 0x7e, 0x52, 0xed, 0xc1, + 0x81, 0x5c, 0x96, 0xea, 0xdc, 0xa3, 0xb7, 0x76, 0x43, 0xaf, 0x7e, 0x0b, 0xf0, 0x77, 0xc0, 0xe4, + 0xc9, 0x59, 0x92, 0xff, 0x8e, 0x7e, 0x40, 0x21, 0xbb, 0xf5, 0xbb, 0x2f, 0xff, 0x04, 0x00, 0x00, + 0xff, 0xff, 0xcc, 0xf1, 0x05, 0x94, 0x2b, 0x04, 0x00, 0x00, } diff --git a/pb/rpc/rpc.proto b/pb/rpc/rpc.proto index 51908b0..aad9cc0 100644 --- a/pb/rpc/rpc.proto +++ b/pb/rpc/rpc.proto @@ -15,7 +15,7 @@ service Poc { // AddPeer message RPCAddPeerReq { string ip = 1; - int32 port = 2; + int64 port = 2; int64 seed = 3; } @@ -37,14 +37,20 @@ message RPCGetSubscribedShardReply { // BroadcastCollation message RPCBroadcastCollationReq { int64 shardID = 1; - int32 number = 2; - int32 size = 3; - int32 period = 4; + int64 number = 2; + int64 size = 3; + int64 period = 4; +} +// RequestCollation +message RPCRequestCollationReq { + int64 shardID = 1; + int64 period = 4; } // StopServer message RPCStopServerReq { } + message RPCReply { string message = 1; bool status = 2; diff --git a/requests.go b/requests.go index 0adfc43..38a7324 100644 --- a/requests.go +++ b/requests.go @@ -36,15 +36,15 @@ func NewRequestProtocol(node *Node) *RequestProtocol { func getCollation( shardID ShardIDType, - period int64, + period int, collationHash string) (*pbmsg.Collation, error) { // FIXME: fake response for now. Shuld query from the saved data. // with // case specifies `shardID`, `period` // and case specifies `collationHash` return &pbmsg.Collation{ - ShardID: shardID, - Period: period, + ShardID: PBInt(shardID), + Period: PBInt(period), Blobs: []byte{}, }, nil } @@ -155,8 +155,8 @@ func (p *RequestProtocol) onCollationRequest(s inet.Stream) { // FIXME: add checks var collation *pbmsg.Collation collation, err := getCollation( - data.GetShardID(), - data.GetPeriod(), + ShardIDType(data.GetShardID()), + int(data.GetPeriod()), data.GetHash(), ) var collationResp *pbmsg.CollationResponse @@ -187,7 +187,7 @@ func (p *RequestProtocol) requestCollation( ctx context.Context, peerID peer.ID, shardID ShardIDType, - period int64, + period int, blobs string) (*pbmsg.Collation, error) { s, err := p.node.NewStream( ctx, @@ -198,8 +198,8 @@ func (p *RequestProtocol) requestCollation( return nil, fmt.Errorf("failed to open new stream %v", err) } req := &pbmsg.CollationRequest{ - ShardID: shardID, - Period: period, + ShardID: PBInt(shardID), + Period: PBInt(period), } if !sendProtoMessage(req, s) { return nil, fmt.Errorf("failed to send request") diff --git a/rpcclient.go b/rpcclient.go index beafc5f..f76133f 100644 --- a/rpcclient.go +++ b/rpcclient.go @@ -9,7 +9,7 @@ import ( "google.golang.org/grpc" ) -func callRPCAddPeer(rpcAddr string, ipAddr string, port int, seed int64) { +func callRPCAddPeer(rpcAddr string, ipAddr string, port int, seed int) { conn, err := grpc.Dial(rpcAddr, grpc.WithInsecure()) if err != nil { log.Fatalf("did not connect: %v", err) @@ -18,8 +18,8 @@ func callRPCAddPeer(rpcAddr string, ipAddr string, port int, seed int64) { client := pbrpc.NewPocClient(conn) addPeerReq := &pbrpc.RPCAddPeerReq{ Ip: ipAddr, - Port: int32(port), - Seed: seed, + Port: PBInt(port), + Seed: PBInt(seed), } log.Printf("rpcclient:AddPeer: sending=%v", addPeerReq) res, err := client.AddPeer(context.Background(), addPeerReq) @@ -95,9 +95,9 @@ func callRPCBroadcastCollation( client := pbrpc.NewPocClient(conn) broadcastCollationReq := &pbrpc.RPCBroadcastCollationReq{ ShardID: shardID, - Number: int32(numCollations), - Size: int32(collationSize), - Period: int32(period), + Number: PBInt(numCollations), + Size: PBInt(collationSize), + Period: PBInt(period), } log.Printf("rpcclient:BroadcastCollation: sending=%v", broadcastCollationReq) res, err := client.BroadcastCollation(context.Background(), broadcastCollationReq) diff --git a/rpcserver.go b/rpcserver.go index abe1fff..7651bfd 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -30,7 +30,7 @@ func (s *server) AddPeer(ctx context.Context, req *pbrpc.RPCAddPeerReq) (*pbrpc. defer span.Finish() log.Printf("rpcserver:AddPeer: receive=%v", req) - _, targetPID, err := makeKey(req.Seed) + _, targetPID, err := makeKey(int(req.Seed)) mAddr := fmt.Sprintf( "/ip4/%s/tcp/%d/ipfs/%s", req.Ip, @@ -151,7 +151,7 @@ func (s *server) BroadcastCollation( // TODO: catching error s.node.broadcastCollation( ShardIDType(shardID), - int64(i), + i, randBytes, ) } diff --git a/shardmanager.go b/shardmanager.go index ba7e2b3..02604d2 100644 --- a/shardmanager.go +++ b/shardmanager.go @@ -333,11 +333,11 @@ func (n *ShardManager) SubscribeShardCollations(shardID ShardIDType) { n.shardCollationsSubs[shardID] = collationsSub } -func (n *ShardManager) broadcastCollation(shardID ShardIDType, period int64, blobs []byte) bool { +func (n *ShardManager) broadcastCollation(shardID ShardIDType, period int, blobs []byte) bool { // create message data data := &pbmsg.Collation{ ShardID: shardID, - Period: period, + Period: PBInt(period), Blobs: blobs, } return n.broadcastCollationMessage(data)