当前位置: 首页>>代码示例>>C#>>正文


C# Network.RequestPublicKey方法代码示例

本文整理汇总了C#中Network.RequestPublicKey方法的典型用法代码示例。如果您正苦于以下问题:C# Network.RequestPublicKey方法的具体用法?C# Network.RequestPublicKey怎么用?C# Network.RequestPublicKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Network的用法示例。


在下文中一共展示了Network.RequestPublicKey方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ProcessCommand

        private string ProcessCommand(Network network, string[] args)
        {
            NetworkInfo networkInfo = null;
            foreach (NetworkInfo n in settings.Networks) {
                if (n.NetworkID == network.NetworkID) {
                    networkInfo = n;
                    break;
                }
            }
            if (networkInfo == null) {
                throw new Exception("EGADS!!");
            }

            string result = String.Empty;
            switch (args[0]) {
                case "key":
                    if (args.Length > 1) {
                        switch (args[1]) {
                            case "list":
                                result += "TRUSTED KEYS\n";
                                foreach (TrustedNodeInfo n in network.TrustedNodes.Values) {
                                    result += "  " + n.NodeID + "\n";
                                }
                                result += "\nUNTRUSTED KEYS\n";
                                foreach (IO.DirectoryInfo dir in new IO.DirectoryInfo("received_keys").GetDirectories()) {
                                    if (dir.Name == network.NetworkID) {
                                        foreach (IO.FileInfo file in dir.GetFiles()) {
                                            result += "  " + file.Name + "\n";
                                        }
                                    }
                                }
                                break;
                            case "trust":
                                if (args.Length > 2) {
                                    string id = args[2];
                                    string keyDir = IO.Path.Combine("received_keys", network.NetworkID);
                                    string keyFile = IO.Path.Combine(keyDir, id + ".mpk");

                                    if (IO.File.Exists(keyFile)) {
                                        PublicKey key = PublicKey.Parse(IO.File.ReadAllText(keyFile));
                                        TrustedNodeInfo nodeInfo = new TrustedNodeInfo(key);

                                        networkInfo.TrustedNodes.Add(nodeInfo.NodeID, nodeInfo);

                                        settings.SaveSettings();
                                        Core.Settings = settings;
                                        IO.File.Delete (keyFile);
                                        result += "Key added!";
                                    } else {
                                        result += "File not found.";
                                    }
                                } else {
                                    result += "Argument(s) expected: keyid";
                                }
                                break;
                            case "request":
                                if (args.Length > 2) {
                                    string nodeid = args[2];
                                    Node node = network.Nodes[nodeid];
                                    if (node != null) {
                                        network.RequestPublicKey(node);
                                        result += "Key requested!";
                                    } else {
                                        result += "Node not found!";
                                    }
                                    break;
                                } else {
                                    result += "Argument(s) expected: nodeid";
                                }
                                break;
                            default:
                                result += "key list - show all keys\n";
                                result += "key trust <id> - trust a key\n";
                                result += "key request <id> - request a user's key\n";
                                break;
                        }
                    } else {
                        result += "Argument expected: key command.";
                    }
                    break;
                case "admin":
                    if (args.Length > 1) {
                        switch (args[1]) {
                            case "list":
                                result += "\nThere are " + settings.AdminIDs.Count + " admins:\n";
                                foreach (string id in settings.AdminIDs) {
                                    TrustedNodeInfo info = networkInfo.TrustedNodes[id];
                                    result += info.Identifier + " (" + id + ")\n";
                                }

                                break;

                            case "add":
                                if (args.Length > 2) {
                                    string id = args[2];
                                    if (!settings.AdminIDs.Contains(id)) {
                                        if (networkInfo.TrustedNodes[id] != null) {
                                            settings.AdminIDs.Add(id);
                                            settings.SaveSettings();
                                        } else {
//.........这里部分代码省略.........
开发者ID:codebutler,项目名称:meshwork,代码行数:101,代码来源:MeshworkDaemon.cs

示例2: network_UserOnline

 private void network_UserOnline(Network network, Node node)
 {
     try {
         if (node.GetTrustedNode() == null && (!IO.File.Exists(GetKeyFileName(network, node.NodeID)))) {
             network.RequestPublicKey(node);
         }
     } catch (Exception ex) {
         LoggingService.LogError("Error in network_UserOnline: " + ex);
     }
 }
开发者ID:codebutler,项目名称:meshwork,代码行数:10,代码来源:MeshworkDaemon.cs


注:本文中的Network.RequestPublicKey方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。