-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
1,871 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Copyright 2022 iFLYTEK. All Rights Reserved. | ||
# # | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# # | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# # | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# ============================================================================== | ||
|
||
from importlib import import_module | ||
from loguru import logger | ||
from iflearner.business.mpc.piss.piss_client_controller import PissClientServicesController | ||
from iflearner.business.mpc.piss.argument import parser | ||
|
||
|
||
if __name__ == "__main__": | ||
args = parser.parse_args() | ||
print(args) | ||
controller = PissClientServicesController(args) | ||
controller.run() | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
ID,Age,Money,Height,Credit_value | ||
10001,18,6.1,1.88,98.6 | ||
10002,19,-99.25,1.76,87 | ||
10003,20,8.6,1.68,99.5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# Copyright 2022 iFLYTEK. All Rights Reserved. | ||
# # | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# # | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# # | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# ============================================================================== | ||
import argparse | ||
import json | ||
from importlib import import_module | ||
from threading import Thread | ||
from typing import Any, Dict, Union | ||
from loguru import logger | ||
import time | ||
|
||
from iflearner.communication.mpc.piss import piss_client_services | ||
from iflearner.business.mpc.piss import piss_strategy_client | ||
from iflearner.communication.base import base_server | ||
from iflearner.communication.mpc.piss import message_type | ||
from iflearner.communication.mpc.piss import piss_pb2, piss_pb2_grpc | ||
from iflearner.business.mpc.piss.piss_client_controller import PissClientController | ||
from iflearner.business.mpc.piss.argument import parser | ||
|
||
if __name__ == "__main__": | ||
|
||
parser = argparse.ArgumentParser() | ||
|
||
parser.add_argument( | ||
"--data", | ||
default='examples/mpc/quickstart_piss/piss_data_test.csv', | ||
type=str, | ||
help="path of data") | ||
|
||
parser.add_argument( | ||
"--param", | ||
default={'10001':'Age', '10002':'Money'}, | ||
type=json.loads, | ||
help="encryption param" | ||
) | ||
parser.add_argument( | ||
"--addr", | ||
default="127.0.0.1:37221", | ||
type=str, | ||
help="address of client service" | ||
) | ||
|
||
parser.add_argument( | ||
"--name", | ||
default="client_querty", | ||
type=str, | ||
help="querty client name" | ||
) | ||
|
||
args = parser.parse_args() | ||
print(args) | ||
controller = PissClientController(args) | ||
#controller.init_data() | ||
controller.start_querty() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from iflearner.business.mpc.piss.piss_aggregate_server import main | ||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Copyright 2022 iFLYTEK. All Rights Reserved. | ||
# # | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# # | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# # | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# ============================================================================== | ||
import argparse | ||
|
||
parser = argparse.ArgumentParser() | ||
|
||
|
||
parser.add_argument( | ||
"--server", | ||
default="127.0.0.1:12095", | ||
type=str, | ||
help="address of aggerating server", | ||
) | ||
|
||
parser.add_argument( | ||
"--name", | ||
default="client003", | ||
type=str, | ||
help="party name of client", | ||
) | ||
|
||
parser.add_argument( | ||
"--addr", | ||
default="127.0.0.1:57221", | ||
type=str, | ||
help="address of client service", | ||
) | ||
|
||
parser.add_argument( | ||
"--data", | ||
default='examples/mpc/quickstart_piss/piss_data_test.csv', | ||
type=str, | ||
help="path of data") | ||
|
||
parser.add_argument( | ||
"--cert", | ||
default=None, | ||
type=str, | ||
help="path of server SSL cert" | ||
"""use secure channel to connect to server if not none""", | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Copyright 2022 iFLYTEK. All Rights Reserved. | ||
# # | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# # | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# # | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# ============================================================================== | ||
import argparse | ||
import json | ||
from importlib import import_module | ||
from threading import Thread | ||
from typing import Any, Dict, Union | ||
|
||
from iflearner.communication.mpc.piss import piss_server | ||
from iflearner.communication.base import base_server | ||
from iflearner.communication.mpc.piss import piss_pb2, piss_pb2_grpc | ||
from iflearner.business.mpc.piss import piss_client_controller | ||
|
||
class PissAggregateServer: | ||
|
||
def __init__(self, addr: str ,party_name: str) -> None: | ||
self._addr = addr | ||
self._party_name = party_name | ||
self._piss_server_inst = piss_server.PissServer(party_name= party_name) | ||
|
||
def run(self) -> None: | ||
"""start piss server""" | ||
base_server.start_server(self._addr,self._piss_server_inst) | ||
|
||
def main(): | ||
parser = argparse.ArgumentParser() | ||
|
||
|
||
parser.add_argument( | ||
"--addr", help="the server address", default="127.0.0.1:12095", type=str | ||
) | ||
parser.add_argument( | ||
"--name", help="the server name", default="server", type=str | ||
) | ||
args = parser.parse_args() | ||
|
||
global server | ||
server = PissAggregateServer(addr = args.addr, party_name= args.name) | ||
server.run() | ||
|
||
if __name__ == "__main__": | ||
main() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# Copyright 2022 iFLYTEK. All Rights Reserved. | ||
# # | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# # | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# # | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# ============================================================================== | ||
import argparse | ||
from importlib import import_module | ||
from typing import Any, Dict, Union | ||
from loguru import logger | ||
|
||
from iflearner.communication.mpc.piss import piss_client_services | ||
from iflearner.communication.base import base_server | ||
from iflearner.communication.mpc.piss import message_type | ||
from iflearner.communication.mpc.piss import piss_pb2 | ||
import grpc | ||
from iflearner.communication.base import base_pb2, base_pb2_grpc,base_server,constant | ||
|
||
|
||
class PissClientServicesController: | ||
|
||
def __init__(self, args: argparse.Namespace) -> None: | ||
|
||
self._args = args | ||
self._piss_client_services_inst = piss_client_services.PissClientServices( | ||
server_addr=self._args.server , | ||
party_name= self._args.name, | ||
route= self._args.addr, | ||
data_path= self._args.data, | ||
cert_path= self._args.cert | ||
) | ||
|
||
def run(self) -> None: | ||
# """REGISTER""" | ||
resp = self._piss_client_services_inst.transport( | ||
type = message_type.MSG_REGISTER, | ||
data = piss_pb2.RegistrationInfo(route = self._args.addr) | ||
) | ||
"""start piss client server""" | ||
if resp.code == 0: | ||
base_server.start_server(self._args.addr,self._piss_client_services_inst) | ||
|
||
class PissClientController: | ||
def __init__(self, args: argparse.Namespace) -> None: | ||
|
||
self._args = args | ||
self._options = [ | ||
("grpc.max_message_length", constant.MAX_MSG_LENGTH), | ||
("grpc.max_send_message_length", constant.MAX_MSG_LENGTH), | ||
("grpc.max_receive_message_length", constant.MAX_MSG_LENGTH), | ||
] | ||
|
||
self._channel = grpc.insecure_channel(self._args.addr, options = self._options) | ||
self._stub = base_pb2_grpc.BaseStub(self._channel) | ||
self._encryption_param = self._args.param | ||
self._data_path = self._args.data | ||
self._party_name = self._args.name | ||
|
||
def init_data(self): | ||
|
||
data = piss_pb2.InitData(data_path = self._data_path) | ||
req = base_pb2.BaseRequest(party_name = self._party_name, | ||
type = message_type.MSG_INIT_DATA, | ||
data = data.SerializeToString()) | ||
resp = self._stub.send(req) | ||
|
||
def start_querty(self): | ||
|
||
#encryption_param = {'10001':'Age', '10002':'Money'} | ||
#encryption_param = json.loads(self._encryption_param) | ||
data = piss_pb2.ShareEncryptionParam(encryption_param = self._encryption_param) | ||
|
||
req = base_pb2.BaseRequest(party_name = self._party_name, | ||
type = message_type.MSG_START_QUERY, | ||
data = data.SerializeToString()) | ||
|
||
resp = self._stub.send(req) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
from abc import ABC | ||
from ast import Return | ||
import code | ||
from enum import IntEnum, auto | ||
import imp | ||
from typing import Any, Dict | ||
|
||
import numpy as np | ||
|
||
import argparse | ||
import json | ||
from importlib import import_module | ||
from threading import Thread | ||
from typing import Any, Dict, Union | ||
from loguru import logger | ||
import time | ||
import grpc | ||
from iflearner.communication.mpc import piss | ||
import threading | ||
|
||
|
||
from iflearner.communication.mpc.piss.piss_exception import PissException | ||
from iflearner.communication.base import base_server | ||
from iflearner.communication.mpc.piss import message_type | ||
from iflearner.communication.mpc.piss import piss_pb2, piss_pb2_grpc | ||
from iflearner.communication.base import base_pb2, base_pb2_grpc,base_server,constant | ||
|
||
|
||
class PissStrategyBase(ABC): | ||
def __init__(self ,cert_path: str, party_name: str,options) -> None: | ||
|
||
self._cert_path = cert_path | ||
self._party_name = party_name | ||
self._options = options | ||
|
||
self._routes: dict = dict() | ||
self._stubs: dict = dict() | ||
self._party_name_list = [] | ||
|
||
self._initiator_party_name: str = str() | ||
self._initiator_route: str = str() | ||
self._initiator_stub = None | ||
|
||
def generate_stub(self, destination_addr: str): | ||
|
||
if self._cert_path is None: | ||
channel = grpc.insecure_channel(destination_addr, options = self._options) | ||
else: | ||
with open(self._cert_path, "rb") as f: | ||
cert_bytes = f.read() | ||
|
||
channel = grpc.secure_channel( | ||
destination_addr, grpc.ssl_channel_credentials(cert_bytes), options = self._options | ||
) | ||
stub = base_pb2_grpc.BaseStub(channel) | ||
return stub |
Oops, something went wrong.