本文整理汇总了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 {
//.........这里部分代码省略.........
示例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);
}
}