Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add common DataStore protocol #24

Merged
merged 25 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
086c601
added start of DataStore
jonbarrow Oct 29, 2023
adec20f
added server PRUDP version checks for response packets
jonbarrow Oct 29, 2023
9953bce
removed method order todo comment. already in ID order
jonbarrow Oct 29, 2023
5544918
added CompletePostObjects
jonbarrow Oct 29, 2023
cb8f1fb
added DeleteObject
jonbarrow Oct 29, 2023
85ac1b2
added GetMetas
jonbarrow Oct 29, 2023
823830b
DeleteObject was always using PRUDPv1
jonbarrow Oct 29, 2023
b643ac5
added TODO comment to PreparePostObject
jonbarrow Oct 29, 2023
a2c1d4f
added PostMetaBinary
jonbarrow Oct 29, 2023
c3d3683
added RateObject
jonbarrow Oct 29, 2023
3bbd382
added SearchObject
jonbarrow Oct 29, 2023
cdfa4a6
remove TODO and delete unsuccessful objects in CompletePostObject
jonbarrow Oct 29, 2023
fc7039b
log an error when upload sizes dont match
jonbarrow Oct 29, 2023
014ad34
URL to url in PrepareGetObject
jonbarrow Oct 29, 2023
e143a8c
properly handle TotalCount and TotalCountType in SearchObject
jonbarrow Oct 29, 2023
4f97f68
added SetDataKeyBase and SetNotifyKeyBase to separate data and notify…
jonbarrow Oct 29, 2023
719cd89
moved minio s3 client to common
jonbarrow Oct 29, 2023
890b9dc
moved VerifyObjectPermission to common
jonbarrow Oct 29, 2023
49bca9e
removed creating zeroed structs manually
jonbarrow Oct 30, 2023
9ed9b13
use FilterPropertiesByResultOption when requesting object data
jonbarrow Oct 30, 2023
271cc3f
misspelled GetObjectSizeByDataID
jonbarrow Oct 30, 2023
444944d
update VerifyObjectPermission to always allow an owner to access thei…
jonbarrow Oct 30, 2023
8095267
unexport DataStore MinIO client
jonbarrow Oct 31, 2023
63149ad
undo incomplete changes to CompletePostObject. Waiting for conversati…
jonbarrow Oct 31, 2023
0df41b9
check owner and upload status in CompletePostObject
jonbarrow Oct 31, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions datastore/change_meta.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package datastore

import (
nex "github.com/PretendoNetwork/nex-go"
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/globals"
datastore "github.com/PretendoNetwork/nex-protocols-go/datastore"
datastore_types "github.com/PretendoNetwork/nex-protocols-go/datastore/types"
)

func changeMeta(err error, client *nex.Client, callID uint32, param *datastore_types.DataStoreChangeMetaParam) uint32 {
if commonDataStoreProtocol.getObjectInfoByDataIDHandler == nil {
common_globals.Logger.Warning("GetObjectInfoByDataID not defined")
return nex.Errors.Core.NotImplemented
}

if commonDataStoreProtocol.updateObjectPeriodByDataIDWithPasswordHandler == nil {
common_globals.Logger.Warning("UpdateObjectPeriodByDataIDWithPassword not defined")
return nex.Errors.Core.NotImplemented
}

if commonDataStoreProtocol.updateObjectMetaBinaryByDataIDWithPasswordHandler == nil {
common_globals.Logger.Warning("UpdateObjectMetaBinaryByDataIDWithPassword not defined")
return nex.Errors.Core.NotImplemented
}

if commonDataStoreProtocol.updateObjectDataTypeByDataIDWithPasswordHandler == nil {
common_globals.Logger.Warning("UpdateObjectDataTypeByDataIDWithPassword not defined")
return nex.Errors.Core.NotImplemented
}

if err != nil {
common_globals.Logger.Error(err.Error())
return nex.Errors.DataStore.Unknown
}

metaInfo, errCode := commonDataStoreProtocol.getObjectInfoByDataIDHandler(param.DataID)
if errCode != 0 {
return errCode
}

// TODO - Is this the right permission?
errCode = commonDataStoreProtocol.VerifyObjectPermission(metaInfo.OwnerID, client.PID(), metaInfo.DelPermission)
if errCode != 0 {
return errCode
}

if param.ModifiesFlag&0x08 != 0 {
errCode = commonDataStoreProtocol.updateObjectPeriodByDataIDWithPasswordHandler(param.DataID, param.Period, param.UpdatePassword)
if errCode != 0 {
return errCode
}
}

if param.ModifiesFlag&0x10 != 0 {
errCode = commonDataStoreProtocol.updateObjectMetaBinaryByDataIDWithPasswordHandler(param.DataID, param.MetaBinary, param.UpdatePassword)
if errCode != 0 {
return errCode
}
}

if param.ModifiesFlag&0x80 != 0 {
errCode = commonDataStoreProtocol.updateObjectDataTypeByDataIDWithPasswordHandler(param.DataID, param.DataType, param.UpdatePassword)
if errCode != 0 {
return errCode
}
}

rmcResponse := nex.NewRMCResponse(datastore.ProtocolID, callID)
rmcResponse.SetSuccess(datastore.MethodChangeMeta, nil)

rmcResponseBytes := rmcResponse.Bytes()

var responsePacket nex.PacketInterface

if commonDataStoreProtocol.server.PRUDPVersion() == 0 {
responsePacket, _ = nex.NewPacketV0(client, nil)
responsePacket.SetVersion(0)
} else {
responsePacket, _ = nex.NewPacketV1(client, nil)
responsePacket.SetVersion(1)
}

responsePacket.SetSource(0xA1)
responsePacket.SetDestination(0xAF)
responsePacket.SetType(nex.DataPacket)
responsePacket.SetPayload(rmcResponseBytes)

responsePacket.AddFlag(nex.FlagNeedsAck)
responsePacket.AddFlag(nex.FlagReliable)

commonDataStoreProtocol.server.Send(responsePacket)

return 0
}
124 changes: 124 additions & 0 deletions datastore/complete_post_object.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
package datastore

import (
"fmt"

nex "github.com/PretendoNetwork/nex-go"
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/globals"
datastore "github.com/PretendoNetwork/nex-protocols-go/datastore"
datastore_types "github.com/PretendoNetwork/nex-protocols-go/datastore/types"
)

func completePostObject(err error, client *nex.Client, callID uint32, param *datastore_types.DataStoreCompletePostParam) uint32 {
if commonDataStoreProtocol.minIOClient == nil {
common_globals.Logger.Warning("MinIOClient not defined")
return nex.Errors.Core.NotImplemented
}

if commonDataStoreProtocol.getObjectInfoByDataIDHandler == nil {
common_globals.Logger.Warning("GetObjectInfoByDataID not defined")
return nex.Errors.Core.NotImplemented
}

if commonDataStoreProtocol.getObjectOwnerByDataIDHandler == nil {
common_globals.Logger.Warning("GetObjectOwnerByDataID not defined")
return nex.Errors.Core.NotImplemented
}

if commonDataStoreProtocol.getObjectSizeByDataIDHandler == nil {
common_globals.Logger.Warning("GetObjectSizeByDataID not defined")
return nex.Errors.Core.NotImplemented
}

if commonDataStoreProtocol.updateObjectUploadCompletedByDataIDHandler == nil {
common_globals.Logger.Warning("UpdateObjectUploadCompletedByDataID not defined")
return nex.Errors.Core.NotImplemented
}

if commonDataStoreProtocol.deleteObjectByDataIDHandler == nil {
common_globals.Logger.Warning("DeleteObjectByDataID not defined")
return nex.Errors.Core.NotImplemented
}

if err != nil {
common_globals.Logger.Error(err.Error())
return nex.Errors.DataStore.Unknown
}

// * If GetObjectInfoByDataID returns data then that means
// * the object has already been marked as uploaded. So do
// * nothing
objectInfo, _ := commonDataStoreProtocol.getObjectInfoByDataIDHandler(param.DataID)
if objectInfo != nil {
return nex.Errors.DataStore.PermissionDenied
}

// * Only allow an objects owner to make this request
ownerPID, errCode := commonDataStoreProtocol.getObjectOwnerByDataIDHandler(param.DataID)
if errCode != 0 {
return errCode
}

if ownerPID != client.PID() {
return nex.Errors.DataStore.PermissionDenied
}

bucket := commonDataStoreProtocol.s3Bucket
key := fmt.Sprintf("%s/%d.bin", commonDataStoreProtocol.s3DataKeyBase, param.DataID)

if param.IsSuccess {
objectSizeS3, err := commonDataStoreProtocol.S3ObjectSize(bucket, key)
if err != nil {
common_globals.Logger.Error(err.Error())
return nex.Errors.DataStore.NotFound
}

objectSizeDB, errCode := commonDataStoreProtocol.getObjectSizeByDataIDHandler(param.DataID)
if errCode != 0 {
return errCode
}

if objectSizeS3 != uint64(objectSizeDB) {
common_globals.Logger.Errorf("Object with DataID %d did not upload correctly! Mismatched sizes", param.DataID)
// TODO - Is this a good error?
return nex.Errors.DataStore.Unknown
}

errCode = commonDataStoreProtocol.updateObjectUploadCompletedByDataIDHandler(param.DataID, true)
if errCode != 0 {
return errCode
}
} else {
errCode := commonDataStoreProtocol.deleteObjectByDataIDHandler(param.DataID)
if errCode != 0 {
return errCode
}
jonbarrow marked this conversation as resolved.
Show resolved Hide resolved
}

rmcResponse := nex.NewRMCResponse(datastore.ProtocolID, callID)
rmcResponse.SetSuccess(datastore.MethodCompletePostObject, nil)

rmcResponseBytes := rmcResponse.Bytes()

var responsePacket nex.PacketInterface

if commonDataStoreProtocol.server.PRUDPVersion() == 0 {
responsePacket, _ = nex.NewPacketV0(client, nil)
responsePacket.SetVersion(0)
} else {
responsePacket, _ = nex.NewPacketV1(client, nil)
responsePacket.SetVersion(1)
}

responsePacket.SetSource(0xA1)
responsePacket.SetDestination(0xAF)
responsePacket.SetType(nex.DataPacket)
responsePacket.SetPayload(rmcResponseBytes)

responsePacket.AddFlag(nex.FlagNeedsAck)
responsePacket.AddFlag(nex.FlagReliable)

commonDataStoreProtocol.server.Send(responsePacket)

return 0
}
85 changes: 85 additions & 0 deletions datastore/complete_post_objects.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package datastore

import (
"fmt"

"github.com/PretendoNetwork/nex-go"
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/globals"
datastore "github.com/PretendoNetwork/nex-protocols-go/datastore"
)

func completePostObjects(err error, client *nex.Client, callID uint32, dataIDs []uint64) uint32 {
if commonDataStoreProtocol.minIOClient == nil {
common_globals.Logger.Warning("MinIOClient not defined")
return nex.Errors.Core.NotImplemented
}

if commonDataStoreProtocol.getObjectSizeByDataIDHandler == nil {
common_globals.Logger.Warning("GetObjectSizeByDataID not defined")
return nex.Errors.Core.NotImplemented
}

if commonDataStoreProtocol.updateObjectUploadCompletedByDataIDHandler == nil {
common_globals.Logger.Warning("UpdateObjectUploadCompletedByDataID not defined")
return nex.Errors.Core.NotImplemented
}

if err != nil {
common_globals.Logger.Error(err.Error())
return nex.Errors.DataStore.Unknown
}

for _, dataID := range dataIDs {
bucket := commonDataStoreProtocol.s3Bucket
key := fmt.Sprintf("%s/%d.bin", commonDataStoreProtocol.s3DataKeyBase, dataID)

objectSizeS3, err := commonDataStoreProtocol.S3ObjectSize(bucket, key)
if err != nil {
common_globals.Logger.Error(err.Error())
return nex.Errors.DataStore.NotFound
}

objectSizeDB, errCode := commonDataStoreProtocol.getObjectSizeByDataIDHandler(dataID)
if errCode != 0 {
return errCode
}

if objectSizeS3 != uint64(objectSizeDB) {
common_globals.Logger.Errorf("Object with DataID %d did not upload correctly! Mismatched sizes", dataID)
// TODO - Is this a good error?
return nex.Errors.DataStore.Unknown
}

errCode = commonDataStoreProtocol.updateObjectUploadCompletedByDataIDHandler(dataID, true)
if errCode != 0 {
return errCode
}
}

rmcResponse := nex.NewRMCResponse(datastore.ProtocolID, callID)
rmcResponse.SetSuccess(datastore.MethodCompletePostObjects, nil)

rmcResponseBytes := rmcResponse.Bytes()

var responsePacket nex.PacketInterface

if commonDataStoreProtocol.server.PRUDPVersion() == 0 {
responsePacket, _ = nex.NewPacketV0(client, nil)
responsePacket.SetVersion(0)
} else {
responsePacket, _ = nex.NewPacketV1(client, nil)
responsePacket.SetVersion(1)
}

responsePacket.SetSource(0xA1)
responsePacket.SetDestination(0xAF)
responsePacket.SetType(nex.DataPacket)
responsePacket.SetPayload(rmcResponseBytes)

responsePacket.AddFlag(nex.FlagNeedsAck)
responsePacket.AddFlag(nex.FlagReliable)

commonDataStoreProtocol.server.Send(responsePacket)

return 0
}
67 changes: 67 additions & 0 deletions datastore/delete_object.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package datastore

import (
"github.com/PretendoNetwork/nex-go"
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/globals"
datastore "github.com/PretendoNetwork/nex-protocols-go/datastore"
datastore_types "github.com/PretendoNetwork/nex-protocols-go/datastore/types"
)

func deleteObject(err error, client *nex.Client, callID uint32, param *datastore_types.DataStoreDeleteParam) uint32 {
if commonDataStoreProtocol.getObjectInfoByDataIDHandler == nil {
common_globals.Logger.Warning("GetObjectInfoByDataID not defined")
return nex.Errors.Core.NotImplemented
}

if commonDataStoreProtocol.deleteObjectByDataIDWithPasswordHandler == nil {
common_globals.Logger.Warning("DeleteObjectByDataIDWithPassword not defined")
return nex.Errors.Core.NotImplemented
}

if err != nil {
common_globals.Logger.Error(err.Error())
return nex.Errors.DataStore.Unknown
}

metaInfo, errCode := commonDataStoreProtocol.getObjectInfoByDataIDHandler(param.DataID)
if errCode != 0 {
return errCode
}

errCode = commonDataStoreProtocol.VerifyObjectPermission(metaInfo.OwnerID, client.PID(), metaInfo.DelPermission)
if errCode != 0 {
return errCode
}

errCode = commonDataStoreProtocol.deleteObjectByDataIDWithPasswordHandler(param.DataID, param.UpdatePassword)
if errCode != 0 {
return errCode
}

rmcResponse := nex.NewRMCResponse(datastore.ProtocolID, callID)
rmcResponse.SetSuccess(datastore.MethodDeleteObject, nil)

rmcResponseBytes := rmcResponse.Bytes()

var responsePacket nex.PacketInterface

if commonDataStoreProtocol.server.PRUDPVersion() == 0 {
responsePacket, _ = nex.NewPacketV0(client, nil)
responsePacket.SetVersion(0)
} else {
responsePacket, _ = nex.NewPacketV1(client, nil)
responsePacket.SetVersion(1)
}

responsePacket.SetSource(0xA1)
responsePacket.SetDestination(0xAF)
responsePacket.SetType(nex.DataPacket)
responsePacket.SetPayload(rmcResponseBytes)

responsePacket.AddFlag(nex.FlagNeedsAck)
responsePacket.AddFlag(nex.FlagReliable)

commonDataStoreProtocol.server.Send(responsePacket)

return 0
}
Loading