private void _network_VirtualPeerSecureChannelException(BitChatNetwork sender, SecureChannelException ex) { if (PeerSecureChannelException != null) { RaiseEventPeerSecureChannelException(ex); } }
private void CreateInvitationPrivateChat(BinaryID hashedPeerEmailAddress, BinaryID networkID, IPEndPoint peerEP, string message) { BitChatNetwork network = new BitChatNetwork(_connectionManager, _trustedRootCertificates, _supportedCryptoOptions, hashedPeerEmailAddress, networkID, null, BitChatNetworkStatus.Offline, peerEP.ToString(), message); BitChat chat = CreateBitChat(network, BinaryID.GenerateRandomID160().ToString(), BinaryID.GenerateRandomID256().ID, 0, null, new BitChatProfile.SharedFileInfo[] { }, _profile.TrackerURIs, true, false, false); RaiseEventBitChatInvitationReceived(chat); }
private void _network_VirtualPeerHasRevokedCertificate(BitChatNetwork sender, InvalidCertificateException ex) { if (PeerHasRevokedCertificate != null) { RaiseEventPeerHasRevokedCertificate(ex); } }
public void RemoveNetwork(BitChatNetwork network) { lock (_networks) { _networks.Remove(network.NetworkID); } }
public void SendBitChatNetworkInvitation(string message) { BinaryID hashedEmailAddress = BitChatNetwork.GetHashedEmailAddress(_connectionManager.Profile.LocalCertificateStore.Certificate.IssuedTo.EmailAddress); byte[] buffer = Encoding.UTF8.GetBytes(message); //send invitation signal with message WriteFrame(SignalType.BitChatNetworkInvitation, hashedEmailAddress, buffer, 0, buffer.Length); }
private void Network_NetworkChanged(BitChatNetwork network, BinaryID newNetworkID) { lock (_chats) { BitChat chat = _chats[network.NetworkID]; _chats.Add(newNetworkID, chat); _chats.Remove(network.NetworkID); } }
public BitChatClient(BitChatProfile profile, Certificate[] trustedRootCertificates, SecureChannelCryptoOptionFlags supportedCryptoOptions) { _profile = profile; _trustedRootCertificates = trustedRootCertificates; _supportedCryptoOptions = supportedCryptoOptions; _maskedEmailAddress = BitChatNetwork.GetMaskedEmailAddress(_profile.LocalCertificateStore.Certificate.IssuedTo.EmailAddress); _profile.ProxyUpdated += profile_ProxyUpdated; _profile.ProfileImageChanged += profile_ProfileImageChanged; }
private void ConnectionManager_TcpRelayPeersAvailable(Connection viaConnection, BinaryID channelName, List <IPEndPoint> peerEPs) { try { BitChatNetwork network = FindBitChatNetwork(viaConnection, channelName); if ((network != null) && (network.Status == BitChatNetworkStatus.Online)) { network.MakeConnection(viaConnection, peerEPs); } } catch { } }
private void _network_VirtualPeerAdded(BitChatNetwork sender, BitChatNetwork.VirtualPeer virtualPeer) { Peer peer = new Peer(virtualPeer, this); lock (_peers) { _peers.Add(peer); } if (PeerAdded != null) { RaiseEventPeerAdded(peer); } }
private void ConnectionManager_BitChatNetworkChannelInvitation(BinaryID hashedPeerEmailAddress, IPEndPoint peerEP, string message) { BinaryID networkID = BitChatNetwork.GetNetworkID(_profile.LocalCertificateStore.Certificate.IssuedTo.EmailAddress, hashedPeerEmailAddress); bool networkExists; lock (_chats) { networkExists = _chats.ContainsKey(networkID); } if (!networkExists) { CreateInvitationPrivateChat(hashedPeerEmailAddress, networkID, peerEP, message); } }
public BitChat CreateBitChat(string networkName, string sharedSecret, BinaryID networkID, Certificate[] knownPeerCerts, BitChatProfile.SharedFileInfo[] sharedFileInfoList, Uri[] trackerURIs) { BitChatNetwork network = new BitChatNetwork(networkName, sharedSecret, networkID, knownPeerCerts, this, this); lock (_networks) { _networks.Add(network.NetworkID, network); } if (trackerURIs == null) { trackerURIs = _profile.TrackerURIs; } return(new BitChat(this, _profile, network, sharedFileInfoList, trackerURIs)); }
public BitChat CreateGroupChat(string networkName, string sharedSecret, bool enableTracking, bool dhtOnlyTracking) { Uri[] trackerURIs; if (dhtOnlyTracking) { trackerURIs = new Uri[] { } } ; else { trackerURIs = _profile.TrackerURIs; } BitChatNetwork network = new BitChatNetwork(_connectionManager, _trustedRootCertificates, _supportedCryptoOptions, networkName, sharedSecret, null, null, new Certificate[] { }, BitChatNetworkStatus.Online); return(CreateBitChat(network, BinaryID.GenerateRandomID160().ToString(), BinaryID.GenerateRandomID256().ID, -1, null, new BitChatProfile.SharedFileInfo[] { }, trackerURIs, enableTracking, false, false)); }
public BitChat CreatePrivateChat(MailAddress peerEmailAddress, string sharedSecret, bool enableTracking, bool dhtOnlyTracking, string invitationMessage) { Uri[] trackerURIs; if (dhtOnlyTracking) { trackerURIs = new Uri[] { } } ; else { trackerURIs = _profile.TrackerURIs; } BitChatNetwork network = new BitChatNetwork(_connectionManager, _trustedRootCertificates, _supportedCryptoOptions, peerEmailAddress, sharedSecret, null, null, new Certificate[] { }, BitChatNetworkStatus.Online, _profile.LocalCertificateStore.Certificate.IssuedTo.EmailAddress.Address, invitationMessage); return(CreateBitChat(network, BinaryID.GenerateRandomID160().ToString(), BinaryID.GenerateRandomID256().ID, 0, null, new BitChatProfile.SharedFileInfo[] { }, trackerURIs, enableTracking, !string.IsNullOrEmpty(invitationMessage), false)); }
private void ConnectionManager_BitChatNetworkChannelRequest(Connection connection, BinaryID channelName, Stream channel) { try { BitChatNetwork network = FindBitChatNetwork(connection, channelName); if (network == null) { channel.Dispose(); return; } network.AcceptConnectionAndJoinNetwork(connection, channel); } catch { channel.Dispose(); } }
internal BitChat(IBitChatManager manager, BitChatProfile profile, BitChatNetwork network, BitChatProfile.SharedFileInfo[] sharedFileInfoList, Uri[] trackerURIs) { _manager = manager; _profile = profile; _network = network; _network.VirtualPeerAdded += _network_VirtualPeerAdded; _network.VirtualPeerHasRevokedCertificate += _network_VirtualPeerHasRevokedCertificate; _network.VirtualPeerSecureChannelException += _network_VirtualPeerSecureChannelException; foreach (BitChatNetwork.VirtualPeer virtualPeer in _network.GetVirtualPeerList()) { Peer peer = new Peer(virtualPeer, this); if (peer.IsSelf) { _selfPeer = peer; } _peers.Add(peer); } foreach (BitChatProfile.SharedFileInfo info in sharedFileInfoList) { try { _sharedFiles.Add(info.FileMetaData.FileID, SharedFile.LoadFile(info, this, _syncCxt)); } catch { } } //start tracking _manager.StartLocalTracking(_network.NetworkID); StartTracking(trackerURIs); //start noop timer _NOOPTimer = new Timer(NOOPTimerCallback, null, NOOP_PACKET_TIME_SECONDS, Timeout.Infinite); //start network update timer _updateNetworkStatusTimer = new Timer(UpdateNetworkStatusCallback, null, NETWORK_STATUS_TIMER_INTERVAL, Timeout.Infinite); _reCheckNetworkStatusTimer = new Timer(ReCheckNetworkStatusCallback, null, Timeout.Infinite, Timeout.Infinite); }
private BitChat CreateBitChat(BitChatNetwork network, string messageStoreID, byte[] messageStoreKey, long groupImageDateModified, byte[] groupImage, BitChatProfile.SharedFileInfo[] sharedFileInfoList, Uri[] trackerURIs, bool enableTracking, bool sendInvitation, bool mute) { BitChat chat; lock (_chats) { if (_chats.ContainsKey(network.NetworkID)) { if (network.Type == BitChatNetworkType.PrivateChat) { throw new BitChatException("Bit Chat for '" + network.NetworkName + "' already exists."); } else { throw new BitChatException("Bit Chat group '" + network.NetworkName + "' already exists."); } } chat = new BitChat(_syncCxt, _localDiscovery, network, messageStoreID, messageStoreKey, groupImageDateModified, groupImage, sharedFileInfoList, trackerURIs, enableTracking, sendInvitation, mute); chat.Leave += BitChat_Leave; chat.SetupTcpRelay += BitChat_SetupTcpRelay; chat.RemoveTcpRelay += BitChat_RemoveTcpRelay; network.NetworkChanged += Network_NetworkChanged; _chats.Add(chat.NetworkID, chat); } if (enableTracking && (network.Status == BitChatNetworkStatus.Online)) { //setup tcp relay for network if available if (_tcpRelayClient != null) { _tcpRelayClient.AddNetwork(network.NetworkID, trackerURIs); } } return(chat); }
private BitChatNetwork FindBitChatNetwork(Connection connection, BinaryID channelName) { //find network by channel name lock (_chats) { foreach (KeyValuePair <BinaryID, BitChat> chat in _chats) { BitChatNetwork network = chat.Value.Network; if (network.Status == BitChatNetworkStatus.Online) { BinaryID computedChannelName = network.GetChannelName(connection.LocalPeerID, connection.RemotePeerID); if (computedChannelName.Equals(channelName)) { return(network); } } } } return(null); }
public void Start() { if (_connectionManager != null) { return; } //set min threads since the default value is too small for client at startup due to multiple chats queuing too many tasks immediately { int minWorker, minIOC; ThreadPool.GetMinThreads(out minWorker, out minIOC); minWorker = Environment.ProcessorCount * 32; ThreadPool.SetMinThreads(minWorker, minIOC); } //verify root certs foreach (Certificate trustedCert in _trustedRootCertificates) { trustedCert.Verify(_trustedRootCertificates); } //verify profile cert _profile.LocalCertificateStore.Certificate.Verify(_trustedRootCertificates); //start connection manager _connectionManager = new ConnectionManager(_profile); _connectionManager.InternetConnectivityStatusChanged += ConnectionManager_InternetConnectivityStatusChanged; _connectionManager.BitChatNetworkChannelInvitation += ConnectionManager_BitChatNetworkChannelInvitation; _connectionManager.BitChatNetworkChannelRequest += ConnectionManager_BitChatNetworkChannelRequest; _connectionManager.TcpRelayPeersAvailable += ConnectionManager_TcpRelayPeersAvailable; //start local peer discovery LocalPeerDiscovery.StartListener(41733); _localDiscovery = new LocalPeerDiscovery(_connectionManager.LocalPort); _localDiscovery.PeerDiscovered += LocalDiscovery_PeerDiscovered; //check inbound invitation tracking ManageInboundInvitationTracking(); foreach (BitChatProfile.BitChatInfo bitChatInfo in _profile.BitChatInfoList) { try { BitChatNetwork network; if (bitChatInfo.Type == BitChatNetworkType.PrivateChat) { if (bitChatInfo.PeerEmailAddress == null) { network = new BitChatNetwork(_connectionManager, _trustedRootCertificates, _supportedCryptoOptions, bitChatInfo.HashedPeerEmailAddress, bitChatInfo.NetworkID, bitChatInfo.NetworkSecret, bitChatInfo.NetworkStatus, bitChatInfo.InvitationSender, bitChatInfo.InvitationMessage); } else { network = new BitChatNetwork(_connectionManager, _trustedRootCertificates, _supportedCryptoOptions, bitChatInfo.PeerEmailAddress, bitChatInfo.SharedSecret, bitChatInfo.NetworkID, bitChatInfo.NetworkSecret, bitChatInfo.PeerCertificateList, bitChatInfo.NetworkStatus, bitChatInfo.InvitationSender, bitChatInfo.InvitationMessage); } } else { network = new BitChatNetwork(_connectionManager, _trustedRootCertificates, _supportedCryptoOptions, bitChatInfo.NetworkName, bitChatInfo.SharedSecret, bitChatInfo.NetworkID, bitChatInfo.NetworkSecret, bitChatInfo.PeerCertificateList, bitChatInfo.NetworkStatus); } BitChat chat = CreateBitChat(network, bitChatInfo.MessageStoreID, bitChatInfo.MessageStoreKey, bitChatInfo.GroupImageDateModified, bitChatInfo.GroupImage, bitChatInfo.SharedFileList, bitChatInfo.TrackerURIs, bitChatInfo.EnableTracking, bitChatInfo.SendInvitation, bitChatInfo.Mute); _chats.Add(chat.NetworkID, chat); } catch { } } //check profile cert revocation ThreadPool.QueueUserWorkItem(CheckCertificateRevocationAsync, new Certificate[] { _profile.LocalCertificateStore.Certificate }); //check trusted root cert revocation ThreadPool.QueueUserWorkItem(CheckCertificateRevocationAsync, _trustedRootCertificates); }