-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDistributedProtocol.cs
More file actions
56 lines (50 loc) · 1.54 KB
/
DistributedProtocol.cs
File metadata and controls
56 lines (50 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System;
using System.Text.Json;
using System.Text.Json.Serialization;
using BitcoinFinder;
namespace BitcoinFinder.Distributed
{
public enum MessageType
{
AGENT_REGISTER,
AGENT_REQUEST_TASK,
SERVER_TASK_ASSIGNED,
SERVER_NO_TASKS,
AGENT_REPORT_PROGRESS,
AGENT_BLOCK_COMPLETED,
AGENT_REPORT_RESULT
}
public class Message
{
public MessageType Type { get; set; }
public string AgentId { get; set; } = string.Empty;
public JsonElement? Data { get; set; }
public DateTime Timestamp { get; set; }
public string ToJson()
{
return JsonSerializer.Serialize(this);
}
public static Message FromJson(string json)
{
return JsonSerializer.Deserialize<Message>(json)!;
}
}
public class BlockTask
{
public int BlockId { get; set; }
public long StartIndex { get; set; }
public long EndIndex { get; set; }
public SearchParameters SearchParams { get; set; } = new SearchParameters();
public string Status { get; set; } = string.Empty;
public string? AssignedToAgent { get; set; }
}
public class AgentInfo
{
public string AgentId { get; set; } = string.Empty;
public string IpAddress { get; set; } = string.Empty;
public string Status { get; set; } = string.Empty;
public int CurrentBlockId { get; set; }
public double Speed { get; set; }
public DateTime LastHeartbeat { get; set; }
}
}