-
Notifications
You must be signed in to change notification settings - Fork 39
/
clear_expired_share.go
56 lines (48 loc) · 1.93 KB
/
clear_expired_share.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
49
50
51
52
53
54
55
56
package event
import (
"context"
"github.com/stratosnet/sds/framework/core"
"github.com/stratosnet/sds/framework/msg/header"
"github.com/stratosnet/sds/framework/utils"
"github.com/stratosnet/sds/pp"
"github.com/stratosnet/sds/pp/api/rpc"
"github.com/stratosnet/sds/pp/file"
"github.com/stratosnet/sds/pp/p2pserver"
"github.com/stratosnet/sds/pp/requests"
"github.com/stratosnet/sds/pp/setting"
"github.com/stratosnet/sds/sds-msg/protos"
)
func ClearExpiredShareLinks(ctx context.Context, walletAddr string, walletPubkey, wsign []byte, reqTime int64) {
if setting.CheckLogin() {
p2pserver.GetP2pServer(ctx).SendMessageToSPServer(ctx, requests.ClearExpiredShareLinksData(
p2pserver.GetP2pServer(ctx).GetP2PAddress().String(), walletAddr, walletPubkey, wsign, reqTime), header.ReqClearExpiredShareLinks)
}
}
func RspClearExpiredShareLinks(ctx context.Context, conn core.WriteCloser) {
pp.DebugLog(ctx, "get RspClearExpiredShareLinks")
var target protos.RspClearExpiredShareLinks
if err := VerifyMessage(ctx, header.RspClearExpiredShareLinks, &target); err != nil {
utils.ErrorLog("failed verifying the message, ", err.Error())
return
}
rpcResult := &rpc.ClearExpiredShareLinksResult{}
// fail to unmarshal data, not able to determine if and which RPC client this is from, let the client timeout
if !requests.UnmarshalData(ctx, &target) {
return
}
// serv the RPC user when the ReqId is not empty
reqId := core.GetRemoteReqId(ctx)
if reqId != "" {
defer file.SetClearExpiredShareLinksResult(target.WalletAddress+reqId, rpcResult)
}
if target.Result.State != protos.ResultState_RES_SUCCESS {
utils.ErrorLog(target.Result.Msg)
rpcResult.Return = rpc.INTERNAL_COMM_FAILURE
return
}
if target.Result.State == protos.ResultState_RES_SUCCESS {
pp.Logf(ctx, "ClearExpiredShareLinks done, %d cleared, %d remaining", target.Cleared, target.NewTotal)
} else {
pp.Log(ctx, "ClearExpiredShareLinks failed ", target.Result.Msg)
}
}