public SocialConnectionManager(SocialNode node, RpcManager rpc, SocialDnsManager sdm, SocialStatsManager ssm, SocialConfig config) { _rpc = rpc; _rpc.AddHandler(RPCID, this); _sdm = sdm; _node = node; _ssm = ssm; _networks = ImmutableDictionary<string, ISocialNetwork>.Empty; _fprs = ImmutableDictionary<string, string>.Empty; _times = ImmutableDictionary<string, System.DateTime>.Empty; _pending = ImmutableList<string>.Empty; _blocked = ImmutableList<string>.Empty; _beat_counter = 0; _auto_allow = config.AutoFriend; _sdm.Sender = this; #if !SVPN_NUNIT _timer = new Timer(TimerHandler, _beat_counter, PERIOD, PERIOD); LoadState(); #endif }
public static new SocialNode CreateNode() { SocialConfig social_config; NodeConfig node_config; IpopConfig ipop_config; RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(); if(File.Exists(CONFIGPATH)) { social_config = Utils.ReadConfig<SocialConfig>(CONFIGPATH); } else { social_config = SocialUtils.CreateConfig(); } node_config = Utils.ReadConfig<NodeConfig>(social_config.BrunetConfig); ipop_config = Utils.ReadConfig<IpopConfig>(social_config.IpopConfig); if(!File.Exists(node_config.Security.KeyPath) || node_config.NodeAddress == null) { node_config.NodeAddress = Utils.GenerateAHAddress().ToString(); Utils.WriteConfig(social_config.BrunetConfig, node_config); SocialUtils.WriteToFile(rsa.ExportCspBlob(true), node_config.Security.KeyPath); } else if(File.Exists(node_config.Security.KeyPath)) { rsa.ImportCspBlob(SocialUtils.ReadFileBytes( node_config.Security.KeyPath)); } SocialNode node = new SocialNode(node_config, ipop_config, rsa); #if !SVPN_NUNIT SocialDnsManager sdm = new SocialDnsManager(node); SocialStatsManager ssm = new SocialStatsManager(node); SocialConnectionManager manager = new SocialConnectionManager(node, node.AppNode.Node.Rpc, sdm, ssm, social_config); JabberNetwork jabber = new JabberNetwork(social_config.JabberID, social_config.JabberPass, social_config.JabberHost, social_config.JabberPort); TestNetwork test = new TestNetwork(); manager.Register("jabber", jabber); manager.Register("test", test); if(social_config.AutoLogin) { manager.Login("jabber", social_config.JabberID, social_config.JabberPass); } HttpInterface http = new HttpInterface(social_config.HttpPort); http.ProcessEvent += manager.ProcessHandler; node._marad.Resolver = sdm; node.Shutdown.OnExit += jabber.Logout; node.Shutdown.OnExit += http.Stop; http.Start(); #endif return node; }
/** * Constructor. * @param brunetConfig configuration file for Brunet P2P library. * @param ipopConfig configuration file for IP over P2P app. */ public SocialNode(NodeConfig brunetConfig, IpopConfig ipopConfig, string certDir, string http_port, string jabber_port, string global_access) : base(brunetConfig, ipopConfig) { _friends = new Dictionary<string, SocialUser>(); _aliases = new Dictionary<string, string>(); _addr_to_key = new Dictionary<string, string>(); _cert_dir = certDir; _http_port = http_port; string cert_path = Path.Combine(certDir, CERTFILENAME); _local_cert = new Certificate(SocialUtils.ReadFileBytes(cert_path)); _local_user = new SocialUser(_local_cert); _local_cert_b64 = Convert.ToBase64String(_local_cert.X509.RawData); _bso.CertificateHandler.AddCACertificate(_local_cert.X509); _bso.CertificateHandler.AddSignedCertificate(_local_cert.X509); _queue = new BlockingQueue(); _snp = new SocialNetworkProvider(this.Dht, _local_user, _local_cert.X509.RawData, _queue, jabber_port); _sdm = new SocialDnsManager(this, _local_user); _srh = new SocialRpcHandler(_node, _local_user, _friends, _queue, _sdm); _scm = new SocialConnectionManager(this, _snp, _srh, http_port, _queue, _sdm); _cert_published = false; _node.ConnectionTable.ConnectionEvent += ConnectHandler; _node.HeartBeatEvent += _scm.HeartBeatHandler; Shutdown.OnExit += _scm.Stop; _local_user.IP = _marad.LocalIP; CreateAlias(_local_user); _marad.MapLocalDNS(_local_user.Alias); _scm.GlobalAccess = (global_access == "on"); LoadCertificates(); }
public static new SocialNode CreateNode() { SocialConfig social_config; NodeConfig node_config; IpopConfig ipop_config; byte[] certData = SocialUtils.ReadFileBytes("local.cert"); string certb64 = Convert.ToBase64String(certData); social_config = Utils.ReadConfig<SocialConfig>("social.config"); node_config = Utils.ReadConfig<NodeConfig>(social_config.BrunetConfig); ipop_config = Utils.ReadConfig<IpopConfig>(social_config.IpopConfig); SocialNode node = new SocialNode(node_config, ipop_config, certb64); HttpInterface http_ui = new HttpInterface(social_config.HttpPort); SocialDnsManager dns_manager = new SocialDnsManager(node); JabberNetwork jabber = new JabberNetwork(social_config.JabberHost, social_config.JabberPort, social_config.AutoFriend, node); http_ui.ProcessEvent += node.ProcessHandler; http_ui.ProcessEvent += jabber.ProcessHandler; http_ui.ProcessEvent += dns_manager.ProcessHandler; node.Shutdown.OnExit += http_ui.Stop; node.Shutdown.OnExit += jabber.Logout; node.SetGlobalBlock(social_config.GlobalBlock); node.LoadState(); if (social_config.AutoLogin) { jabber.Login(social_config.JabberID, social_config.JabberPass); } http_ui.Start(); return node; }
/** * Constructor. * @param node the social node. * @param provider the identity provider. * @param network the social network. * @param port the port number for the HTTP interface. * @param srh the social rpc handler. */ public SocialConnectionManager(SocialNode node,SocialNetworkProvider snp, SocialRpcHandler srh, string port, BlockingQueue queue, SocialDnsManager sdm) { _snode = node; _snp = snp; _http = new HttpInterface(port); _http.ProcessEvent += ProcessHandler; _http.Start(); _srh = srh; _queue = queue; _sdm = sdm; _main_thread = new Thread(Start); _main_thread.Start(); _delims = new char[] {'\n',','}; _last_update = DateTime.MinValue; _last_store = _last_update; _last_publish = _last_update; _last_ping = _last_update; _heartbeat_counter = 0; }
/** * Constructor. * @param node the p2p node. * @param localUser the local user object. * @param friends the list of friends. */ public SocialRpcHandler(StructuredNode node, SocialUser localUser, Dictionary<string, SocialUser> friends, BlockingQueue queue, SocialDnsManager sdm) { _node = node; _rpc = node.Rpc; _rpc.AddHandler("SocialVPN", this); _local_user = localUser; _friends = friends; _queue = queue; _sdm = sdm; }