Skip to content

Commit

Permalink
Merge pull request #44 from TRON-US/BTFS-1137
Browse files Browse the repository at this point in the history
BTFS-1137
  • Loading branch information
taiyangc authored Dec 5, 2019
2 parents 3c87186 + 98cb69b commit d543468
Show file tree
Hide file tree
Showing 13 changed files with 367 additions and 163 deletions.
1 change: 0 additions & 1 deletion crypto/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,3 @@ func GetPubKeyFromPeerId(pid string) (ic.PubKey, error) {
}
return pubKey, nil
}

2 changes: 1 addition & 1 deletion crypto/crypto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

const (
KeyString = "CAISIJFNZZd5ZSvi9OlJP/mz/vvUobvlrr2//QN4DzX/EShP"
KeyString = "CAISIJFNZZd5ZSvi9OlJP/mz/vvUobvlrr2//QN4DzX/EShP"
EncryptKey = "Tron2theMoon1234"
)

Expand Down
191 changes: 96 additions & 95 deletions protos/hub/hub.pb.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion protos/hub/hub.proto
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ option java_package = "io.btfs.hub";
import "github.com/tron-us/protobuf/gogoproto/gogo.proto";
import "google/protobuf/timestamp.proto";

service HubQuery {
service HubQueryService {
rpc GetSettings(SettingsReq) returns (SettingsResp);
rpc GetHosts(HostsReq) returns (HostsResp);
}
Expand Down
235 changes: 190 additions & 45 deletions protos/status/status.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions protos/status/status.proto
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ service Status {
rpc CollectError(NodeError) returns (google.protobuf.Empty);
}

service StatusService {
rpc UpdateMetrics(SignedMetrics) returns (google.protobuf.Empty);
rpc CollectHealth(NodeHealth) returns (google.protobuf.Empty);
rpc CollectError(NodeError) returns (google.protobuf.Empty);
}

message SignedMetrics {
bytes public_key = 1;
bytes signature = 2;
Expand Down
30 changes: 18 additions & 12 deletions utils/grpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ import (
"strings"
"time"

"github.com/tron-us/go-btfs-common/protos/escrow"
"github.com/tron-us/go-btfs-common/protos/guard"
"github.com/tron-us/go-btfs-common/protos/hub"
"github.com/tron-us/go-btfs-common/protos/status"
escrowpb "github.com/tron-us/go-btfs-common/protos/escrow"
guardpb "github.com/tron-us/go-btfs-common/protos/guard"
hubpb "github.com/tron-us/go-btfs-common/protos/hub"
sharedpb "github.com/tron-us/go-btfs-common/protos/shared"
statuspb "github.com/tron-us/go-btfs-common/protos/status"

"google.golang.org/grpc"
"google.golang.org/grpc/connectivity"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/health/grpc_health_v1"
)

const (
Expand Down Expand Up @@ -47,14 +49,18 @@ func (g *ClientBuilder) doWithContext(ctx context.Context, f interface{}) error
return errors.New("failed to get connection")
}
switch v := f.(type) {
case func(context.Context, status.StatusClient) error:
return v(ctx, status.NewStatusClient(conn))
case func(context.Context, hub.HubQueryClient) error:
return v(ctx, hub.NewHubQueryClient(conn))
case func(context.Context, guard.GuardServiceClient) error:
return v(ctx, guard.NewGuardServiceClient(conn))
case func(context.Context, escrow.EscrowServiceClient) error:
return v(ctx, escrow.NewEscrowServiceClient(conn))
case func(context.Context, statuspb.StatusServiceClient) error:
return v(ctx, statuspb.NewStatusServiceClient(conn))
case func(context.Context, hubpb.HubQueryServiceClient) error:
return v(ctx, hubpb.NewHubQueryServiceClient(conn))
case func(context.Context, guardpb.GuardServiceClient) error:
return v(ctx, guardpb.NewGuardServiceClient(conn))
case func(context.Context, escrowpb.EscrowServiceClient) error:
return v(ctx, escrowpb.NewEscrowServiceClient(conn))
case func(ctx context.Context, client sharedpb.RuntimeServiceClient) error:
return v(ctx, sharedpb.NewRuntimeServiceClient(conn))
case func(ctx context.Context, client grpc_health_v1.HealthClient) error:
return v(ctx, grpc_health_v1.NewHealthClient(conn))
default:
return fmt.Errorf("illegal function: %T", f)
}
Expand Down
6 changes: 4 additions & 2 deletions utils/grpc/escrow.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package grpc

import (
"context"
"github.com/tron-us/go-btfs-common/protos/escrow"

escrowpb "github.com/tron-us/go-btfs-common/protos/escrow"
)

func EscrowClient(addr string) *EscrowClientBuilder {
Expand All @@ -13,6 +14,7 @@ type EscrowClientBuilder struct {
ClientBuilder
}

func (g *EscrowClientBuilder) WithContext(ctx context.Context, f func(ctx context.Context, client escrow.EscrowServiceClient) error) error {
func (g *EscrowClientBuilder) WithContext(ctx context.Context, f func(ctx context.Context,
client escrowpb.EscrowServiceClient) error) error {
return g.doWithContext(ctx, f)
}
6 changes: 4 additions & 2 deletions utils/grpc/guard.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package grpc

import (
"context"
"github.com/tron-us/go-btfs-common/protos/guard"

guardpb "github.com/tron-us/go-btfs-common/protos/guard"
)

func GuardClient(addr string) *GuardClientBuilder {
Expand All @@ -13,6 +14,7 @@ type GuardClientBuilder struct {
ClientBuilder
}

func (g *GuardClientBuilder) WithContext(ctx context.Context, f func(ctx context.Context, client guard.GuardServiceClient) error) error {
func (g *GuardClientBuilder) WithContext(ctx context.Context, f func(ctx context.Context,
client guardpb.GuardServiceClient) error) error {
return g.doWithContext(ctx, f)
}
19 changes: 19 additions & 0 deletions utils/grpc/health_check.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package grpc

import (
"context"
"google.golang.org/grpc/health/grpc_health_v1"
)

func HealthCheckClient(addr string) *HealthCheckClientBuilder {
return &HealthCheckClientBuilder{builder(addr)}
}

type HealthCheckClientBuilder struct {
ClientBuilder
}

func (g *HealthCheckClientBuilder) WithContext(ctx context.Context, f func(ctx context.Context,
client grpc_health_v1.HealthClient) error) error {
return g.doWithContext(ctx, f)
}
Loading

0 comments on commit d543468

Please sign in to comment.