-
Notifications
You must be signed in to change notification settings - Fork 39
/
sp_maintenance.go
48 lines (42 loc) · 1.44 KB
/
sp_maintenance.go
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
package event
import (
"context"
"time"
"github.com/stratosnet/sds/framework/client/cf"
"github.com/stratosnet/sds/framework/core"
"github.com/stratosnet/sds/framework/msg/header"
"github.com/stratosnet/sds/framework/utils"
"github.com/stratosnet/sds/pp/network"
"github.com/stratosnet/sds/pp/p2pserver"
"github.com/stratosnet/sds/pp/requests"
"github.com/stratosnet/sds/sds-msg/protos"
)
func NoticeSpUnderMaintenance(ctx context.Context, conn core.WriteCloser) {
var target protos.NoticeSpUnderMaintenance
if err := VerifyMessage(ctx, header.NoticeSpUnderMaintenance, &target); err != nil {
utils.ErrorLog("failed verifying the message, ", err.Error())
return
}
if !requests.UnmarshalData(ctx, &target) {
return
}
switch conn := conn.(type) {
case *core.ServerConn:
utils.DebugLog("Ignore NoticeSpUnderMaintenance in ServerConn")
return
case *cf.ClientConn:
if conn.GetName() != p2pserver.GetP2pServer(ctx).GetSpName() {
utils.DebugLog("Ignore NoticeSpUnderMaintenance from non SP node")
return
}
if target.MaintenanceType == int32(protos.SpMaintenanceType_CONSENSUS) {
utils.Logf("SP[%v] is currently under maintenance, maintenance_type: %v",
target.SpP2PAddress, protos.SpMaintenanceType_CONSENSUS.String())
// record SpMaintenance
triggerSpSwitch := p2pserver.GetP2pServer(ctx).RecordSpMaintenance(target.SpP2PAddress, time.Now())
if triggerSpSwitch {
network.GetPeer(ctx).ChangeSp(ctx)()
}
}
}
}