# FedCrow: Federated-Learning-Based Data Privacy Preservation in Crowd Sensing
## 3 FedCrow Design
### Secure Federated-Learning Framework Construction  
The construction of the federated-learning framework was designed using TensorFlow, which included the construction of artificial intelligence models, model fusion, data synchronization, data transmission, and multi-threaded network communication. In federated learning, the artificial intelligence model can be replaced according to requirements, and model fusion is achieved using a weighted average method. Federated-learning model training is a cyclical process, and thus, model fusion needs to ensure that the data fused each time are from the same batch of clients; otherwise, it may cause missing client models and inaccuracies in the overall model. Data synchronization and transmission use a multi-threaded network communication mode. Model fusion utilizes the method of merging all the participating client-side models using the mean value of the crowd's intelligence perception.  
During model fusion, it is necessary to identify which client the model belongs to and merge them based on the weights assigned to different client IDs. Before transmitting the models, all clients establish a connection with the server and send their respective ID numbers to ensure the effective filtering of legitimate clients. Model fusion is then achieved by taking the mean of the models from different clients, considering their respective weights. Data synchronization is determined based on the number of iterations of the client models. (During the first iteration, it is necessary to verify whether all client models have completed one iteration. During the second iteration, the check should ensure that all client models have completed two iterations, and so on).  
The data transmission between the server and clients in federated learning is implemented using socket technology and the TCP/IP protocol. In federated learning, the server needs to collaborate with multiple clients. However, standard sockets can only support one-to-one communication, and cannot handle concurrent connections. To address this limitation, the SocketServer technology internally incorporates multi-threading and multi-processing techniques, enabling the server to simultaneously handle multiple client socket requests. Therefore, the server utilizes SocketServer to facilitate network transmission. Once the SocketServer is running, it continuously waits for client connections until the participating users connect to the server to receive tasks and models. Each client then performs local training using the tasks and initial models received from the server. Finally, all clients send their trained results back to the server.  
The data exchange process in federated-learning systems may lead to unnecessary data leakage. To address this issue, encryption technology can be utilized to perform computations on encrypted data during the model-training process. This approach helps to construct a secure federated-learning framework for protecting the security of crowdsourced data. By studying the data encryption methods used in federated learning and analyzing the principles and characteristics of additive homomorphic encryption algorithms, multiplicative homomorphic encryption algorithms, and differential privacy, we can choose suitable methods to protect data security based on the application scenarios of crowd sensing. When dealing with large amounts of data, differential privacy methods should be preferred to ensure data security. When dealing with small amounts of data, homomorphic encryption methods can be considered.