未验证 提交 af9f949d 编写于 作者: D Dong Daxiang 提交者: GitHub

Merge pull request #84 from kaih70/master

fix net io recv bug & add example for data alignment
......@@ -138,6 +138,9 @@ public:
if (ret < 0) {
throw std::runtime_error("socket error: recv, errno: " +
std::to_string(errno));
} else if (ret == 0) {
throw std::runtime_error("socket error: 0 byte recved, "
"socket shutdown by peer");
}
recved += ret;
}
......
## Data Alignment Tool
This is an example of using the `alignment` function to build a command line tool of PSI (Private Set Intersection).
### Usage
```bash
python align.py --party_id=$PARTY_ID --endpoints=$END_POINTS --data_file=$FILE_NAME [--is_receiver]
```
### Example
Take data alignment between two parties , e.g., Alice (whose party_id is 0, IP address is 'A.A.A.A', port is 11111) and Bob (whose party_id is 1, IP address is 'B.B.B.B', port is 22222), as an example. Alice and Bob would like to find the intersection of alice_data.txt and bob_data.txt respectively, and Bob is intended to receive the final result.
On each party:
* **Alice**
```bash
python align.py --party_id=0 --endpoints=0:A.A.A.A:11111,1:B.B.B.B:22222 --data_file=alice_data.txt
```
* **Bob**
```bash
python align.py --party_id=1 --endpoints=0:A.A.A.A:11111,1:B.B.B.B:22222 --data_file=bob_data.txt --is_receiver
# Copyright (c) 2020 PaddlePaddle Authors. 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.
"""
Data alignment.
"""
import argparse
import paddle_fl.mpc.data_utils.alignment as alignment
def parse_args():
"""
Parse arguments.
"""
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--party_id", type=int, help="the id of this party")
parser.add_argument("--endpoints", type=str,
default='0:127.0.0.1:11111,1:127.0.0.1:22222',
help="id:ip:port info")
parser.add_argument("--data_file", type=str, help="data file")
parser.add_argument("--is_receiver", action='store_true', help="whether is receiver")
args = parser.parse_args()
return args
def do_align(args):
"""
Do alignment.
"""
# read data from file
input_set = set()
for line in open(args.data_file, 'r'):
input_set.add(line.strip())
# do alignment
result = alignment.align(input_set=input_set,
party_id=args.party_id,
endpoints=args.endpoints,
is_receiver=args.is_receiver)
return result
if __name__ == '__main__':
# use signal for interrupt from keyboard
import signal
signal.signal(signal.SIGINT, signal.SIG_DFL)
args = parse_args()
print('ARGUMENTS: party_id={}, endpoints={}, is_receiver={}, data_file={}'
.format(args.party_id, args.endpoints, args.is_receiver, args.data_file))
align_rst = do_align(args)
print("Alignment result is: {}".format(align_rst))
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册