Skip to content

Commit

Permalink
Updating local server.
Browse files Browse the repository at this point in the history
  • Loading branch information
rodoufu committed Feb 27, 2020
1 parent 837dc1e commit 25258a0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion spec/cpp/src/p2p/P2PServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ grpc::Status P2PServiceImpl::register_me(
servers.emplace(registered);
cout << me << " is registering: " << registered << endl;


writer->Write(stringToUrl(me));
for (auto &server : servers) {
writer->Write(stringToUrl(server));
Expand All @@ -24,6 +23,7 @@ grpc::Status P2PServiceImpl::register_me(

grpc::Status P2PServiceImpl::update_services(
::grpc::ServerContext *context, ::grpc::ServerReaderWriter<::p2p::Url, ::p2p::Url> *stream) {
cout << me << " is updating its services " << endl;
p2p::Url url;
while (stream->Read(&url)) {
servers.emplace(urlToString(&url));
Expand Down
14 changes: 14 additions & 0 deletions spec/cpp/src/p2p/mainP2P.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,20 @@ int main(int argc, char **argv) {
while (reader->Read(&peerUrl)) {
addPeer(urlToString(&peerUrl));
}
if (!reader->Finish().ok()) {
cout << "There was a problem connecting to " << peerName << endl;
peersSet.erase(peerName);
}
}

if (!peersSet.empty()) {
auto stub = P2P::NewStub(CreateChannel(serverAddress, InsecureChannelCredentials()));
ClientContext context;
auto stream = stub->update_services(&context);
for (auto &peerName: peersSet) {
stream->Write(stringToUrl(peerName));
}
stream->Finish();
}
}
});
Expand Down

0 comments on commit 25258a0

Please sign in to comment.