Documentation
¶
Overview ¶
Package pir 简化pir服务的部署和使用,基于 sudoclient.SudoClient 封装的gRPC接口实现。
Server 、Client 分别封装了pir server,pir client相关的gRPC接口调用。
部署 Pir Server Example ¶
下面是创建并部署pir server service的example。
clientF1, err := sudoclient.NewSudoClient(context.TODO(), sudoclient.WithGrpcEndpoint("localhost:8071"), sudoclient.WithHTTPEndpoint("http://localhost:7857"), sudoclient.WithAccount("admin", "sudosudo"), ) if err != nil { // TODO: Handle error. } factoryF1 := NewPirFactory(clientF1) // 创建并等待pir server service部署完成 pirServerF1, err := factoryF1.NewPirServer(context.TODO(), "IDENTITY_NAME_HERE", enums.SVCType_PIR, &protopir.DataModeParams{ Params: &protopir.DataModeParams_VtableParams{ VtableParams: &protopir.VtableModeParams{ VtableId: 7, }, }, }, []string{"ID"}, []string{"age"}, 10, true, )
Index ¶
- type Client
- func (c *Client) Delete(ctx context.Context) error
- func (c *Client) Deploy(ctx context.Context, blocking bool) error
- func (c *Client) Factor3SVerify(ctx context.Context, query *online_service.Factor3SVerifyRequest) (*online_service.Factor3SVerifyResponse, error)
- func (c *Client) ID() uint64
- func (c *Client) IsActive(ctx context.Context) (bool, error)
- func (c *Client) Name() string
- func (c *Client) Pir(ctx context.Context, queries []*pir.PirRequest_KeyColumn) (*pir.PirResponse, error)
- func (c *Client) ServiceID() string
- func (c *Client) Status(ctx context.Context) (enums.PirService_Status, error)
- func (c *Client) TerminateService(ctx context.Context) error
- func (c *Client) Token() string
- func (c *Client) WaitForReady(ctx context.Context) error
- type Factory
- func (f *Factory) CreatePirClient(ctx context.Context, serverParty, serverPath, serverServiceID, tokenStr string, ...) (*Client, error)
- func (f *Factory) CreatePirServer(ctx context.Context, identityName string, svcType enums.SVCType, ...) (*Server, error)
- func (f *Factory) NewPirClient(ctx context.Context, serverParty, serverPath, serverServiceID, tokenStr string, ...) (*Client, error)
- func (f *Factory) NewPirServer(ctx context.Context, identityName string, svcType enums.SVCType, ...) (*Server, error)
- type Manager
- func (m *Manager) GetClients(ctx context.Context, query *pir.GetPirClientServicesRequst) ([]*Client, error)
- func (m *Manager) GetServers(ctx context.Context, query *pir.GetServerServicesRequest) ([]*Server, error)
- func (m *Manager) ListAPIUsages(ctx context.Context, req *basic_api_usage.ListAPIUsagesRequest) (*basic_api_usage.ListAPIUsagesResponse, error)
- func (m *Manager) UpsertUsageNotifyReceiver(ctx context.Context, req *basic_api_usage.UpsertAPIUsageReceiverRequest) error
- type Server
- func (s *Server) Delete(ctx context.Context) error
- func (s *Server) Deploy(ctx context.Context, blocking bool) error
- func (s *Server) DisableClientToken(ctx context.Context, tokenStr string) error
- func (s *Server) EnableClientToken(ctx context.Context, tokenStr string) error
- func (s *Server) GetServiceID() uint64
- func (s *Server) ID() uint64
- func (s *Server) IsActive(ctx context.Context) (bool, error)
- func (s *Server) Name() string
- func (s *Server) NewClientToken(ctx context.Context, partyID string) (string, error)
- func (s *Server) ServiceID() uint64
- func (s *Server) Status(ctx context.Context) (enums.PirService_Status, error)
- func (s *Server) TerminateService(ctx context.Context) error
- func (s *Server) UpdateServerData(ctx context.Context, dataParam *pir.DataModeParams) error
- func (s *Server) WaitForReady(ctx context.Context, interval time.Duration) error
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct { *sudoclient.SudoClient // contains filtered or unexported fields }
Client 封装了关于pir client service的gRPC接口,可用于client service管理和pir查询。
func (*Client) Factor3SVerify ¶
func (c *Client) Factor3SVerify( ctx context.Context, query *online_service.Factor3SVerifyRequest, ) (*online_service.Factor3SVerifyResponse, error)
Factor3SVerify 三要素查询,grpc接口的简单封装,query参数不用设置subPath字段。
Example ¶
package main import ( "context" "crypto/tls" "fmt" "net/http" "google.golang.org/grpc" "google.golang.org/grpc/credentials" "github.com/lvyangyang/sudo-sdk-go/v2/pkg/pir" "github.com/lvyangyang/sudo-sdk-go/v2/pkg/sudoclient" "github.com/lvyangyang/sudo-sdk-go/v2/protobuf/basic/protobuf/service/enums" protopir "github.com/lvyangyang/sudo-sdk-go/v2/protobuf/basic/protobuf/virtualservice/platformpb/pir" "github.com/lvyangyang/sudo-sdk-go/v2/protobuf/online_service" ) func main() { tlsCfg := tls.Config{InsecureSkipVerify: true} transportCred := credentials.NewTLS(&tlsCfg) grpcTransportOpt := grpc.WithTransportCredentials(transportCred) httpTransport := &http.Transport{ TLSClientConfig: &tlsCfg, } //=================server side==================== // prepare server side sudoClient client1, err := sudoclient.NewSudoClient(context.TODO(), sudoclient.WithGrpcEndpoint("grpc.dist-lyy-f1.dist.sudoprivacy.cn:30443"), sudoclient.WithHTTPEndpoint("https://dist-lyy-f1.dist.sudoprivacy.cn:30443"), sudoclient.WithAccount("admin", "sudosudo"), sudoclient.WithGrpcDialOption(grpcTransportOpt), sudoclient.WithHTTPTransport(httpTransport), ) if err != nil { // TODO: Handle error. } factoryF1 := pir.NewPirFactory(client1) // New pir server(blocking,idempotent by identityName) server, err := factoryF1.NewPirServer(context.TODO(), "lyy-server-test11", enums.SVCType_FACTOR3s, &protopir.DataModeParams{ Params: &protopir.DataModeParams_ApiParams{ ApiParams: &protopir.APIModeParams{ Url: "http://10.0.1.40:9123", Path: "/api/mock/data", AuthParams: &protopir.AuthParams{ AuthMethod: enums.AuthMethod_NO_AUTH, }, }, }, }, []string{"phone_md5"}, []string{"id_md5", "name_md5"}, 10, true, ) if err != nil { // TODO: Handle error. } // prepare client token token, err := server.NewClientToken(context.TODO(), "dist-lyy-f2") if err != nil { // TODO: Handle error. } serviceID := server.GetServiceID() //=================client side==================== // prepare client side sudoClient clientF2, err := sudoclient.NewSudoClient(context.TODO(), sudoclient.WithGrpcEndpoint("grpc.dist-lyy-f2.dist.sudoprivacy.cn:30443"), sudoclient.WithHTTPEndpoint("https://dist-lyy-f2.dist.sudoprivacy.cn:30443"), sudoclient.WithAccount("admin", "sudosudo"), sudoclient.WithGrpcDialOption(grpcTransportOpt), sudoclient.WithHTTPTransport(httpTransport), ) if err != nil { // TODO: Handle error. } factoryF2 := pir.NewPirFactory(clientF2) // new client(blocking,idempotent by token) client, err := factoryF2.NewPirClient(context.TODO(), "dist-lyy-f1", "wss://dist-lyy-f1.dist.sudoprivacy.cn:30443/ws", // 如果是 http 则配置为ws fmt.Sprintf("%d", serviceID), token, enums.SVCType_FACTOR3s, true, ) if err != nil { // TODO: Handle error. } // 三要素查询 query := &online_service.Factor3SVerifyRequest{ PhoneMd5: "63b78922bef3d161d2e617080e233011", IdMd5: "4c28b1a6e8bb7cdc6d6050c61a748802", NameMd5: "3a30b24a583acdb203ab1092c793cdc2", } _, err = client.Factor3SVerify(context.TODO(), query) if err != nil { // TODO: Handle error. } // ============release all resoure=============== err = client.Delete(context.TODO()) err = server.Delete(context.TODO()) factoryF1.Close() factoryF2.Close() }
Output:
func (*Client) Pir ¶
func (c *Client) Pir(ctx context.Context, queries []*pir.PirRequest_KeyColumn) (*pir.PirResponse, error)
Pir 查询。
Example ¶
package main import ( "context" "fmt" "github.com/lvyangyang/sudo-sdk-go/v2/pkg/pir" "github.com/lvyangyang/sudo-sdk-go/v2/pkg/sudoclient" "github.com/lvyangyang/sudo-sdk-go/v2/protobuf/basic/protobuf/service/enums" protopir "github.com/lvyangyang/sudo-sdk-go/v2/protobuf/basic/protobuf/virtualservice/platformpb/pir" ) func main() { //=================server side==================== // prepare server side sudoClient sudoClientF1, err := sudoclient.NewSudoClient(context.TODO(), sudoclient.WithGrpcEndpoint("localhost:8071"), sudoclient.WithHTTPEndpoint("http://localhost:7857"), sudoclient.WithAccount("admin", "sudosudo"), ) if err != nil { // TODO: Handle error. } factoryF1 := pir.NewPirFactory(sudoClientF1) // New pir pirServerF1(blocking,idempotent by identityName) pirServerF1, err := factoryF1.NewPirServer(context.TODO(), "IDENTITY_NAME_HERE", enums.SVCType_PIR, &protopir.DataModeParams{ Params: &protopir.DataModeParams_VtableParams{ VtableParams: &protopir.VtableModeParams{ VtableId: 7, }, }, }, []string{"ID"}, []string{"age"}, 10, true, ) // prepare client token token, err := pirServerF1.NewClientToken(context.TODO(), "party-f2") serviceID := pirServerF1.GetServiceID() //=================client side==================== // prepare client side sudoClient sudoClientF2, err := sudoclient.NewSudoClient(context.TODO(), sudoclient.WithGrpcEndpoint("localhost:18071"), sudoclient.WithHTTPEndpoint("http://localhost:17857"), sudoclient.WithAccount("admin", "sudosudo"), ) if err != nil { // TODO: Handle error. } factoryF2 := pir.NewPirFactory(sudoClientF2) // new pirClientF2(blocking,idempotent by token) pirClientF2, err := factoryF2.NewPirClient(context.TODO(), "party-f1", "ws://localhost:7857/ws", // 服务方nginx地址,https入口需配置为wss fmt.Sprintf("%d", serviceID), token, enums.SVCType_PIR, true, ) if err != nil { // TODO: Handle error. } query := []*protopir.PirRequest_KeyColumn{} query = append(query, &protopir.PirRequest_KeyColumn{ Values: []string{"13380"}, }) query = append(query, &protopir.PirRequest_KeyColumn{ Values: []string{"17816"}, }) // do pir request _, err = pirClientF2.Pir(context.TODO(), query) if err != nil { // TODO: Handle error. } // ============release all resoure=============== err = pirClientF2.Delete(context.TODO()) err = pirServerF1.Delete(context.TODO()) factoryF1.Close() factoryF2.Close() }
Output:
func (*Client) TerminateService ¶
TerminateService 仅终结service。service未删除,之后还可以重新部署。
type Factory ¶
type Factory struct {
*sudoclient.SudoClient
}
Factory 是对 sudoclient.SudoClient 的简单封装,提供创建pir Server/Client方法。
func NewPirFactory ¶
func NewPirFactory(client *sudoclient.SudoClient) *Factory
NewPirFactory 返回一个简单封装 sudoclient.SudoClient 的 Factory 。
func (*Factory) CreatePirClient ¶
func (f *Factory) CreatePirClient( ctx context.Context, serverParty, serverPath, serverServiceID, tokenStr string, svcType enums.SVCType, ) (*Client, error)
CreatePirClient 创建pir client。 参数配置参考 Factory.NewPirClient 。
func (*Factory) CreatePirServer ¶
func (f *Factory) CreatePirServer( ctx context.Context, identityName string, svcType enums.SVCType, dataParam *pir.DataModeParams, keyColumns []string, labelColumns []string, indiscernibilityDegree uint64, ) (*Server, error)
CreatePirServer 创建pir server。 参数配置参考 Factory.NewPirServer 。
func (*Factory) NewPirClient ¶
func (f *Factory) NewPirClient( ctx context.Context, serverParty, serverPath, serverServiceID, tokenStr string, svcType enums.SVCType, blocking bool, ) (*Client, error)
NewPirClient 创建并部署client service。
如果设置blocking,阻塞等待直到service部署完成。
serverParty 设置pir服务端partyID。
serverPath 设置服务端url地址。比如"ws://localhost:7857/ws"。
serverServiceID 设置服务端serviceID,需要从服务端pir server读取。
tokenStr 设置服务端提供的token,需要服务端pir server提前为客户端party创建,参考 Server.NewClientToken 。
svcType 设置 pir 或三要素服务。
func (*Factory) NewPirServer ¶
func (f *Factory) NewPirServer( ctx context.Context, identityName string, svcType enums.SVCType, dataParam *pir.DataModeParams, keyColumns []string, labelColumns []string, indiscernibilityDegree uint64, blocking bool, ) (*Server, error)
NewPirServer 创建并部署 pir server。
如果设置blocking,阻塞等待直到service部署完成。
identityName 指定pir server service名称。
svcType 设置 pir 或三要素服务。
dataParam 配置提供服务的数据来源。 如果使用vtable,使用数牍隐私计算平台上已经存在的,也可以通过 sudoclient.BasicSudoClient.CreateVtableFromLocalFile 、 sudoclient.BasicSudoClient.CreateVtableFromDB 提前创建。 vtable属性可以通过 github.com/lvyangyang/sudo-sdk-go/v2/protobuf/basic/protobuf/virtualservice/platformpb.FurnaceClient.ListVtables 查询。
keyColumns 指定pir匹配列。
labelColumns 设置pir查询列。
indiscernibilityDegree 设置pir不可区分度。
type Manager ¶
type Manager struct {
Factory
}
Manager 是对 Factory 的简单封装,封装管控相关接口。
func NewManager ¶
NewManager 返回一个简单封装 sudoclient.SudoClient 的 Manager 。
func (*Manager) GetClients ¶
func (m *Manager) GetClients(ctx context.Context, query *pir.GetPirClientServicesRequst) ([]*Client, error)
GetClients 查询 Client , 根据输入的过滤参数,可能返回0、1个 或多个 Client。
func (*Manager) GetServers ¶
func (m *Manager) GetServers(ctx context.Context, query *pir.GetServerServicesRequest) ([]*Server, error)
GetServers 查询 Server ,根据输入的过滤参数,可能返回0个、1个 或多个 Server。
func (*Manager) ListAPIUsages ¶
func (m *Manager) ListAPIUsages( ctx context.Context, req *basic_api_usage.ListAPIUsagesRequest, ) (*basic_api_usage.ListAPIUsagesResponse, error)
ListAPIUsages 是对grpc接口的简单封装。
func (*Manager) UpsertUsageNotifyReceiver ¶
func (m *Manager) UpsertUsageNotifyReceiver( ctx context.Context, req *basic_api_usage.UpsertAPIUsageReceiverRequest, ) error
UpsertUsageNotifyReceiver 是对 grpc 接口的简单封装。
type Server ¶
type Server struct { *sudoclient.SudoClient // contains filtered or unexported fields }
Server 封装了关于pir server service的gRPC接口。 用于service的部署、终结,和token创建、停用等操作。
func (*Server) DisableClientToken ¶
DisableClientToken 停用token。
func (*Server) EnableClientToken ¶
EnableClientToken 启用token。
func (*Server) GetServiceID ¶
获取serviceID,serviceID是pir server service的属性。
func (*Server) NewClientToken ¶
New ClientToken 为客户端参与方创建token。 token用于部署client端服务。 允许为同一party创建多个token,不同token的client端service的pir查询计量会区别统计。 token创建后默认处于启用状态。
func (*Server) TerminateService ¶
TerminateService 仅终结service。
func (*Server) UpdateServerData ¶
UpdateServerData 更新server service数据,grpc 接口的简单封装,更新过程中原来的数据正常提供服务。 更新状态可通过 Server.Status 查询。
Example ¶
package main import ( "context" "crypto/tls" "net/http" "google.golang.org/grpc" "google.golang.org/grpc/credentials" "github.com/lvyangyang/sudo-sdk-go/v2/pkg/pir" "github.com/lvyangyang/sudo-sdk-go/v2/pkg/sudoclient" protopir "github.com/lvyangyang/sudo-sdk-go/v2/protobuf/basic/protobuf/virtualservice/platformpb/pir" ) func main() { tlsCfg := tls.Config{InsecureSkipVerify: true} transportCred := credentials.NewTLS(&tlsCfg) grpcTransportOpt := grpc.WithTransportCredentials(transportCred) httpTransport := &http.Transport{ TLSClientConfig: &tlsCfg, } client1, err := sudoclient.NewSudoClient(context.TODO(), sudoclient.WithGrpcEndpoint("grpc.dist-lyy-f1.dist.sudoprivacy.cn:30443"), sudoclient.WithHTTPEndpoint("https://dist-lyy-f1.dist.sudoprivacy.cn:30443"), sudoclient.WithAccount("admin", "sudosudo"), sudoclient.WithGrpcDialOption(grpcTransportOpt), sudoclient.WithHTTPTransport(httpTransport), ) if err != nil { // TODO: Handle error. } factory1 := pir.NewPirFactory(client1) manager := pir.NewManager(*factory1) servers, err := manager.GetServers(context.TODO(), &protopir.GetServerServicesRequest{ Query: &protopir.ServerQueryOption{ Id: 14, }, }) if err != nil { // TODO: Handle error. } err = servers[0].UpdateServerData(context.TODO(), &protopir.DataModeParams{ Params: &protopir.DataModeParams_VtableParams{ VtableParams: &protopir.VtableModeParams{ // new Vtable VtableId: 3, }, }, }) if err != nil { // TODO: Handle error. } }
Output: