-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmessages.py
88 lines (69 loc) · 2.51 KB
/
messages.py
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import time
import socket
class BaseMessage(object):
AppendEntries = 0
RequestVote = 1
RequestVoteResponse = 2
AppendEntriesResponse = 3
def __init__(self, sender, receiver, term):
self.sender = sender
self.receiver = receiver
self.term = term
class RequestVoteMsg(BaseMessage):
def __init__(self, sender, receiver, term, data):
BaseMessage.__init__(self, sender, receiver, term)
self.data = data
self.type = BaseMessage.RequestVote
class VoteResponseMsg(BaseMessage):
def __init__(self, sender, receiver, term, data):
BaseMessage.__init__(self, sender, receiver, term)
self.type = BaseMessage.RequestVoteResponse
self.data = data
class AppendEntriesMsg(BaseMessage):
def __init__(self, sender, receiver, term, entries, commitIndex, prevLogIndex, prevLogTerm):
BaseMessage.__init__(self, sender, receiver, term)
self.type = BaseMessage.AppendEntries
self.entries = entries
self.commitIndex = commitIndex
self.prevLogTerm = prevLogTerm
self.prevLogIndex = prevLogIndex
class AppendEntriesResponseMsg(BaseMessage):
def __init__(self, sender, receiver, term, success, matchIndex):
BaseMessage.__init__(self, sender, receiver, term)
self.success = success
self.type = BaseMessage.AppendEntriesResponse
self.matchIndex = matchIndex
class LogEntry(object):
def __init__(self, term, command, addr, uuid, _type = 0):
self.term = term
self.command = command
self.uuid = uuid
self.addr = addr
self.type = _type
class Request(object):
"""docstring for Request"""
def __init__(self, request_msg, uuid = 0):
self.request_msg = request_msg
self.type = 'client'
self.uuid = uuid
class RequestRedirect(Request):
def __init__(self, request_msg, uuid, addr):
self.request_msg = request_msg
self.uuid = uuid
self.addr = addr
self.type = 'redirect'
class ServerConfig(object):
def __init__(self, poolsize, currentTerm, votedFor, log, peers):
self.poolsize = poolsize
self.currentTerm = currentTerm
self.votedFor = votedFor
self.log = log
self.peers = peers
# self.new_quorom = new_quorom
class ConfigChange(object):
def __init__(self, new_config, uuid, phase, addr=None):
self.new_config = new_config
self.uuid = uuid
self.addr = addr
self.phase = phase
self.type = 'change'