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

feat: Migrate to new nex-go types #47

Merged
merged 4 commits into from
Jan 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 4 additions & 4 deletions datastore/change_meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types"
)

func (commonProtocol *CommonProtocol) changeMeta(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreChangeMetaParam) (*nex.RMCMessage, *nex.Error) {
func (commonProtocol *CommonProtocol) changeMeta(err error, packet nex.PacketInterface, callID uint32, param datastore_types.DataStoreChangeMetaParam) (*nex.RMCMessage, *nex.Error) {
if commonProtocol.GetObjectInfoByDataID == nil {
common_globals.Logger.Warning("GetObjectInfoByDataID not defined")
return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error")
Expand Down Expand Up @@ -47,21 +47,21 @@ func (commonProtocol *CommonProtocol) changeMeta(err error, packet nex.PacketInt
return nil, errCode
}

if param.ModifiesFlag.PAND(0x08) != 0 {
if uint32(param.ModifiesFlag) & 0x08 != 0 {
errCode = commonProtocol.UpdateObjectPeriodByDataIDWithPassword(param.DataID, param.Period, param.UpdatePassword)
if errCode != nil {
return nil, errCode
}
}

if param.ModifiesFlag.PAND(0x10) != 0 {
if uint32(param.ModifiesFlag) & 0x10 != 0 {
errCode = commonProtocol.UpdateObjectMetaBinaryByDataIDWithPassword(param.DataID, param.MetaBinary, param.UpdatePassword)
if errCode != nil {
return nil, errCode
}
}

if param.ModifiesFlag.PAND(0x80) != 0 {
if uint32(param.ModifiesFlag) & 0x80 != 0 {
errCode = commonProtocol.UpdateObjectDataTypeByDataIDWithPassword(param.DataID, param.DataType, param.UpdatePassword)
if errCode != nil {
return nil, errCode
Expand Down
10 changes: 5 additions & 5 deletions datastore/complete_post_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types"
)

func (commonProtocol *CommonProtocol) completePostObject(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreCompletePostParam) (*nex.RMCMessage, *nex.Error) {
func (commonProtocol *CommonProtocol) completePostObject(err error, packet nex.PacketInterface, callID uint32, param datastore_types.DataStoreCompletePostParam) (*nex.RMCMessage, *nex.Error) {
if commonProtocol.minIOClient == nil {
common_globals.Logger.Warning("MinIOClient not defined")
return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error")
Expand Down Expand Up @@ -51,8 +51,8 @@ func (commonProtocol *CommonProtocol) completePostObject(err error, packet nex.P
// * If GetObjectInfoByDataID returns data then that means
// * the object has already been marked as uploaded. So do
// * nothing
objectInfo, _ := commonProtocol.GetObjectInfoByDataID(param.DataID)
if objectInfo != nil {
_, errCode := commonProtocol.GetObjectInfoByDataID(param.DataID)
if errCode == nil {
return nil, nex.NewError(nex.ResultCodes.DataStore.PermissionDenied, "change_error")
}

Expand All @@ -62,14 +62,14 @@ func (commonProtocol *CommonProtocol) completePostObject(err error, packet nex.P
return nil, errCode
}

if ownerPID != connection.PID().LegacyValue() {
if ownerPID != uint32(connection.PID()) {
return nil, nex.NewError(nex.ResultCodes.DataStore.PermissionDenied, "change_error")
}

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

if param.IsSuccess.Value {
if param.IsSuccess {
objectSizeS3, err := commonProtocol.S3ObjectSize(bucket, key)
if err != nil {
common_globals.Logger.Error(err.Error())
Expand Down
20 changes: 7 additions & 13 deletions datastore/complete_post_objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
datastore "github.com/PretendoNetwork/nex-protocols-go/v2/datastore"
)

func (commonProtocol *CommonProtocol) completePostObjects(err error, packet nex.PacketInterface, callID uint32, dataIDs *types.List[*types.PrimitiveU64]) (*nex.RMCMessage, *nex.Error) {
func (commonProtocol *CommonProtocol) completePostObjects(err error, packet nex.PacketInterface, callID uint32, dataIDs types.List[types.UInt64]) (*nex.RMCMessage, *nex.Error) {
if commonProtocol.minIOClient == nil {
common_globals.Logger.Warning("MinIOClient not defined")
return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error")
Expand All @@ -35,42 +35,36 @@ func (commonProtocol *CommonProtocol) completePostObjects(err error, packet nex.

var errorCode *nex.Error

dataIDs.Each(func(_ int, dataID *types.PrimitiveU64) bool {
for _, dataID := range dataIDs {
bucket := commonProtocol.S3Bucket
key := fmt.Sprintf("%s/%d.bin", commonProtocol.s3DataKeyBase, dataID)

objectSizeS3, err := commonProtocol.S3ObjectSize(bucket, key)
if err != nil {
common_globals.Logger.Error(err.Error())
errorCode = nex.NewError(nex.ResultCodes.DataStore.NotFound, "change_error")

return true
break
}

objectSizeDB, errCode := commonProtocol.GetObjectSizeByDataID(dataID)
if errCode != nil {
errorCode = errCode

return true
break
}

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?
errorCode = nex.NewError(nex.ResultCodes.DataStore.Unknown, "change_error")

return true
break
}

errCode = commonProtocol.UpdateObjectUploadCompletedByDataID(dataID, true)
if errCode != nil {
errorCode = errCode

return true
break
}

return false
})
}

if errorCode != nil {
return nil, errorCode
Expand Down
2 changes: 1 addition & 1 deletion datastore/delete_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types"
)

func (commonProtocol *CommonProtocol) deleteObject(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreDeleteParam) (*nex.RMCMessage, *nex.Error) {
func (commonProtocol *CommonProtocol) deleteObject(err error, packet nex.PacketInterface, callID uint32, param datastore_types.DataStoreDeleteParam) (*nex.RMCMessage, *nex.Error) {
if commonProtocol.GetObjectInfoByDataID == nil {
common_globals.Logger.Warning("GetObjectInfoByDataID not defined")
return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error")
Expand Down
6 changes: 3 additions & 3 deletions datastore/get_meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types"
)

func (commonProtocol *CommonProtocol) getMeta(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreGetMetaParam) (*nex.RMCMessage, *nex.Error) {
func (commonProtocol *CommonProtocol) getMeta(err error, packet nex.PacketInterface, callID uint32, param datastore_types.DataStoreGetMetaParam) (*nex.RMCMessage, *nex.Error) {
if commonProtocol.GetObjectInfoByPersistenceTargetWithPassword == nil {
common_globals.Logger.Warning("GetObjectInfoByPersistenceTargetWithPassword not defined")
return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error")
Expand All @@ -26,11 +26,11 @@ func (commonProtocol *CommonProtocol) getMeta(err error, packet nex.PacketInterf
connection := packet.Sender()
endpoint := connection.Endpoint()

var pMetaInfo *datastore_types.DataStoreMetaInfo
var pMetaInfo datastore_types.DataStoreMetaInfo
var errCode *nex.Error

// * Real server ignores PersistenceTarget if DataID is set
if param.DataID.Value == 0 {
if param.DataID == 0 {
pMetaInfo, errCode = commonProtocol.GetObjectInfoByPersistenceTargetWithPassword(param.PersistenceTarget, param.AccessPassword)
} else {
pMetaInfo, errCode = commonProtocol.GetObjectInfoByDataIDWithPassword(param.DataID, param.AccessPassword)
Expand Down
23 changes: 9 additions & 14 deletions datastore/get_metas.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types"
)

func (commonProtocol *CommonProtocol) getMetas(err error, packet nex.PacketInterface, callID uint32, dataIDs *types.List[*types.PrimitiveU64], param *datastore_types.DataStoreGetMetaParam) (*nex.RMCMessage, *nex.Error) {
func (commonProtocol *CommonProtocol) getMetas(err error, packet nex.PacketInterface, callID uint32, dataIDs types.List[types.UInt64], param datastore_types.DataStoreGetMetaParam) (*nex.RMCMessage, *nex.Error) {
if commonProtocol.GetObjectInfoByDataID == nil {
common_globals.Logger.Warning("GetObjectInfoByDataID not defined")
return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error")
Expand All @@ -24,41 +24,36 @@ func (commonProtocol *CommonProtocol) getMetas(err error, packet nex.PacketInter

// TODO - Verify if param.PersistenceTarget is respected? It wouldn't make sense here but who knows

pMetaInfo := types.NewList[*datastore_types.DataStoreMetaInfo]()
pResults := types.NewList[*types.QResult]()

pMetaInfo.Type = datastore_types.NewDataStoreMetaInfo()
pResults.Type = types.NewQResult(0)
pMetaInfo := types.NewList[datastore_types.DataStoreMetaInfo]()
pResults := types.NewList[types.QResult]()

// * param has an AccessPassword, but it goes unchecked here.
// * The password would need to be the same for every object
// * in the input array, which doesn't make any sense. Assuming
// * it's unused until proven otherwise

dataIDs.Each(func(_ int, dataID *types.PrimitiveU64) bool {
for _, dataID := range dataIDs {
objectInfo, errCode := commonProtocol.GetObjectInfoByDataID(dataID)

if errCode != nil {
objectInfo = datastore_types.NewDataStoreMetaInfo()

pResults.Append(types.NewQResultError(errCode.ResultCode))
pResults = append(pResults, types.NewQResultError(errCode.ResultCode))
} else {
errCode = commonProtocol.VerifyObjectPermission(objectInfo.OwnerID, connection.PID(), objectInfo.Permission)
if errCode != nil {
objectInfo = datastore_types.NewDataStoreMetaInfo()

pResults.Append(types.NewQResultError(errCode.ResultCode))
pResults = append(pResults, types.NewQResultError(errCode.ResultCode))
} else {
pResults.Append(types.NewQResultSuccess(nex.ResultCodes.DataStore.Unknown))
pResults = append(pResults, types.NewQResultSuccess(nex.ResultCodes.DataStore.Unknown))
}

objectInfo.FilterPropertiesByResultOption(param.ResultOption)
}

pMetaInfo.Append(objectInfo)

return false
})
pMetaInfo = append(pMetaInfo, objectInfo)
}

rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings())

Expand Down
27 changes: 11 additions & 16 deletions datastore/get_metas_multiple_param.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types"
)

func (commonProtocol *CommonProtocol) getMetasMultipleParam(err error, packet nex.PacketInterface, callID uint32, params *types.List[*datastore_types.DataStoreGetMetaParam]) (*nex.RMCMessage, *nex.Error) {
func (commonProtocol *CommonProtocol) getMetasMultipleParam(err error, packet nex.PacketInterface, callID uint32, params types.List[datastore_types.DataStoreGetMetaParam]) (*nex.RMCMessage, *nex.Error) {
if commonProtocol.GetObjectInfoByPersistenceTargetWithPassword == nil {
common_globals.Logger.Warning("GetObjectInfoByPersistenceTargetWithPassword not defined")
return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error")
Expand All @@ -27,18 +27,15 @@ func (commonProtocol *CommonProtocol) getMetasMultipleParam(err error, packet ne
connection := packet.Sender()
endpoint := connection.Endpoint()

pMetaInfo := types.NewList[*datastore_types.DataStoreMetaInfo]()
pResults := types.NewList[*types.QResult]()
pMetaInfo := types.NewList[datastore_types.DataStoreMetaInfo]()
pResults := types.NewList[types.QResult]()

pMetaInfo.Type = datastore_types.NewDataStoreMetaInfo()
pResults.Type = types.NewQResult(0)

params.Each(func(_ int, param *datastore_types.DataStoreGetMetaParam) bool {
var objectInfo *datastore_types.DataStoreMetaInfo
for _, param := range params {
var objectInfo datastore_types.DataStoreMetaInfo
var errCode *nex.Error

// * Real server ignores PersistenceTarget if DataID is set
if param.DataID.Value == 0 {
if param.DataID == 0 {
objectInfo, errCode = commonProtocol.GetObjectInfoByPersistenceTargetWithPassword(param.PersistenceTarget, param.AccessPassword)
} else {
objectInfo, errCode = commonProtocol.GetObjectInfoByDataIDWithPassword(param.DataID, param.AccessPassword)
Expand All @@ -47,24 +44,22 @@ func (commonProtocol *CommonProtocol) getMetasMultipleParam(err error, packet ne
if errCode != nil {
objectInfo = datastore_types.NewDataStoreMetaInfo()

pResults.Append(types.NewQResultError(errCode.ResultCode))
pResults = append(pResults, types.NewQResultError(errCode.ResultCode))
} else {
errCode = commonProtocol.VerifyObjectPermission(objectInfo.OwnerID, connection.PID(), objectInfo.Permission)
if errCode != nil {
objectInfo = datastore_types.NewDataStoreMetaInfo()

pResults.Append(types.NewQResultError(errCode.ResultCode))
pResults = append(pResults, types.NewQResultError(errCode.ResultCode))
} else {
pResults.Append(types.NewQResultSuccess(nex.ResultCodes.DataStore.Unknown))
pResults = append(pResults, types.NewQResultSuccess(nex.ResultCodes.DataStore.Unknown))
}

objectInfo.FilterPropertiesByResultOption(param.ResultOption)
}

pMetaInfo.Append(objectInfo)

return false
})
pMetaInfo = append(pMetaInfo, objectInfo)
}

rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings())

Expand Down
12 changes: 5 additions & 7 deletions datastore/post_meta_binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types"
)

func (commonProtocol *CommonProtocol) postMetaBinary(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStorePreparePostParam) (*nex.RMCMessage, *nex.Error) {
func (commonProtocol *CommonProtocol) postMetaBinary(err error, packet nex.PacketInterface, callID uint32, param datastore_types.DataStorePreparePostParam) (*nex.RMCMessage, *nex.Error) {
// * This method looks to function identically to DataStore::PreparePostObject,
// * except the only difference being it doesn't return an S3 upload URL. This
// * needs to be verified though, as there are other methods in the family such
Expand Down Expand Up @@ -41,23 +41,21 @@ func (commonProtocol *CommonProtocol) postMetaBinary(err error, packet nex.Packe
}

// TODO - Should this be moved to InitializeObjectByPreparePostParam?
param.RatingInitParams.Each(func(_ int, ratingInitParamWithSlot *datastore_types.DataStoreRatingInitParamWithSlot) bool {
for _ , ratingInitParamWithSlot := range param.RatingInitParams {
errCode = commonProtocol.InitializeObjectRatingWithSlot(dataID, ratingInitParamWithSlot)
if errCode != nil {
common_globals.Logger.Errorf("Error code on rating init: %s", errCode.Error())
return true
break
}

return false
})
}

if errCode != nil {
return nil, errCode
}

rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings())

rmcResponseStream.WritePrimitiveUInt64LE(dataID)
rmcResponseStream.WriteUInt64LE(dataID)

rmcResponseBody := rmcResponseStream.Bytes()

Expand Down
10 changes: 4 additions & 6 deletions datastore/prepare_get_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types"
)

func (commonProtocol *CommonProtocol) prepareGetObject(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStorePrepareGetParam) (*nex.RMCMessage, *nex.Error) {
func (commonProtocol *CommonProtocol) prepareGetObject(err error, packet nex.PacketInterface, callID uint32, param datastore_types.DataStorePrepareGetParam) (*nex.RMCMessage, *nex.Error) {
if commonProtocol.GetObjectInfoByDataID == nil {
common_globals.Logger.Warning("GetObjectInfoByDataID not defined")
return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error")
Expand Down Expand Up @@ -57,13 +57,11 @@ func (commonProtocol *CommonProtocol) prepareGetObject(err error, packet nex.Pac
pReqGetInfo := datastore_types.NewDataStoreReqGetInfo()

pReqGetInfo.URL = types.NewString(url.String())
pReqGetInfo.RequestHeaders = types.NewList[*datastore_types.DataStoreKeyValue]()
pReqGetInfo.Size = objectInfo.Size.Copy().(*types.PrimitiveU32)
pReqGetInfo.RequestHeaders = types.NewList[datastore_types.DataStoreKeyValue]()
pReqGetInfo.Size = objectInfo.Size.Copy().(types.UInt32)
pReqGetInfo.RootCACert = types.NewBuffer(commonProtocol.RootCACert)
pReqGetInfo.DataID = param.DataID

pReqGetInfo.RequestHeaders.Type = datastore_types.NewDataStoreKeyValue()
pReqGetInfo.RequestHeaders.SetFromData(requestHeaders)
pReqGetInfo.RequestHeaders = requestHeaders

rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings())

Expand Down
Loading
Loading