private void OnResponseReceive(object sender, MessageEventArgs e) { fLogger.WriteDebug(string.Format("Response received: {0}", e.EndPoint)); var pr = FindPeer(e.EndPoint.Address); fForm.OnMessageReceived(pr, e.Data.EncodeAsString()); var resp = e.Data.Get <BString>("r"); string respType = (resp != null) ? resp.ToString() : ""; switch (respType) { case "handshake": /*var pr = FindPeer(e.Peer.Address); * if (pr != null) { * pr.State = PeerState.Checked; * SendGetPeerInfoQuery(pr); * }*/ break; case "getpeerinfo": var args = e.Data.Get <BDictionary>("rv"); var peerInfo = new PeerProfile(); peerInfo.Load(args); fForm.OnMessageReceived(pr, peerInfo.UserName); fForm.OnMessageReceived(pr, peerInfo.Country); fForm.OnMessageReceived(pr, peerInfo.TimeZone); fForm.OnMessageReceived(pr, peerInfo.Languages); break; } }
public Peer(IPAddress address, int port) { Address = address; EndPoint = new IPEndPoint(address, port); State = PeerState.Unknown; Profile = new PeerProfile(); }
private void InitializePeers() { fShowConnectionInfo = fDatabase.GetParameterBool("show_connection_info"); fLocalPeer = AddPeer(fPublicEndPoint, fProfile); fLocalPeer.State = PeerState.Unknown; fLocalPeer.Presence = fDatabase.LoadPresence(); var dbPeers = fDatabase.LoadPeers(); foreach (var rp in dbPeers) { var remoteProfile = new PeerProfile(); remoteProfile.NodeId = DHTId.Parse(rp.node_id); remoteProfile.UserName = rp.user_name; remoteProfile.Country = rp.country; remoteProfile.Languages = rp.langs; remoteProfile.TimeZone = rp.timezone; remoteProfile.Email = rp.email; remoteProfile.PublicKey = rp.public_key; var remotePeer = AddPeer(Utilities.ParseIPEndPoint(rp.last_endpoint), remoteProfile); remotePeer.IsLocal = false; remotePeer.State = PeerState.Unknown; remotePeer.Presence = PresenceStatus.Offline; } }
private Peer AddPeer(IPEndPoint peerEndPoint, PeerProfile profile = null) { lock (fPeers) { Peer peer = new Peer(peerEndPoint, profile); peer.IsLocal = CheckLocalAddress(peerEndPoint.Address); if (!peer.IsLocal) { fLogger.WriteInfo("Found new peer: {0}", peerEndPoint); } fPeers.Add(peer); return(peer); } }
public static BDictionary CreateGetPeerInfoResponse() { var data = new BDictionary(); data.Add("y", "r"); data.Add("r", "getpeerinfo"); var retvals = new BDictionary(); var peerInfo = new PeerProfile(); peerInfo.ResetSystem(); peerInfo.Save(retvals); data.Add("rv", retvals); return(data); }
public Peer(IPEndPoint peerEndPoint, PeerProfile profile) { EndPoint = peerEndPoint; State = PeerState.Unknown; Profile = (profile == null) ? new PeerProfile() : profile; }
public void AddProfile(PeerProfile peerProfile) { // TODO: add and check existing }
public static BDictionary CreateGetPeerInfoResponse(BString transactionID, byte[] nodeId, PeerProfile peerProfile) { var data = new BDictionary(); data.Add("t", transactionID); data.Add("y", "r"); var r = new BDictionary(); r.Add("q", "get_peer_info"); r.Add("id", new BString(nodeId)); peerProfile.Save(r); data.Add("r", r); return(data); }