-
Notifications
You must be signed in to change notification settings - Fork 11
/
appwsid.go
44 lines (37 loc) · 1.48 KB
/
appwsid.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
/*
* Copyright (c) 2020-present unTill Pro, Ltd.
* @author Denis Gribanov
*/
package coreutils
import (
"fmt"
"hash/crc32"
"github.com/voedger/voedger/pkg/istructs"
)
func GetAppWSID(wsid istructs.WSID, numAppWorkspaces istructs.NumAppWorkspaces) istructs.WSID {
baseWSID := wsid.BaseWSID()
appWSNumber := baseWSID % istructs.WSID(numAppWorkspaces)
baseAppWSID := istructs.FirstBaseAppWSID + appWSNumber
// problem: app workspaces are automatically created in the main cluster on VVM launch
// request to an another cluster -> there are no App Workspaces yet
// it is ok for now because App Workspaces should be created on deply an app in the new cluster
// we're using Main Cluster only
return istructs.NewWSID(istructs.MainClusterID, baseAppWSID)
}
func CRC16(entity []byte) uint16 {
return uint16(crc32.ChecksumIEEE(entity) & CRC16Mask)
}
// for Login use NullWSID as ownerWSID
func GetPseudoWSID(ownerWSID istructs.WSID, entity string, clusterID istructs.ClusterID) istructs.WSID {
if ownerWSID != 0 {
entity = fmt.Sprint(ownerWSID) + "/" + entity
}
crc16 := CRC16([]byte(entity))
return istructs.NewWSID(clusterID, istructs.WSID(crc16))
}
// resulting pseudoWSID leads to the initial appWSID
// note: there could be many different pseudoWSIDs that leads to the same appWSID
func AppWSIDToPseudoWSID(appWSID istructs.WSID) (pseudoWSID istructs.WSID) {
appWSNumber := appWSID.BaseWSID() - istructs.FirstBaseAppWSID
return istructs.NewWSID(istructs.MainClusterID, appWSNumber)
}