From 9f56417fbe3d85118733d04bfb7c25cc498eda69 Mon Sep 17 00:00:00 2001 From: anaswara Date: Thu, 18 Jun 2026 18:35:50 +0530 Subject: [PATCH 1/3] key added --- httpwrapper/httpwrapper.go | 10 +++++++- middleware/3gpp_Sbi_Request_Info.go | 39 +++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 middleware/3gpp_Sbi_Request_Info.go diff --git a/httpwrapper/httpwrapper.go b/httpwrapper/httpwrapper.go index 7a40404..050acd3 100644 --- a/httpwrapper/httpwrapper.go +++ b/httpwrapper/httpwrapper.go @@ -12,6 +12,7 @@ import ( "os" "time" + "github.com/5GC-DEV/util-cdac/logger" "github.com/pkg/errors" "golang.org/x/net/http2" "golang.org/x/net/http2/h2c" @@ -57,10 +58,17 @@ func NewHttp2Server(bindAddr string, preMasterSecretLogPath string, handler http return nil, errors.New("server needs handler to handle request") } - h2Server := &http2.Server{ + /*h2Server := &http2.Server{ // TODO: extends the idle time after re-use openapi client IdleTimeout: 1 * time.Millisecond, + }*/ + h2Server := &http2.Server{ + IdleTimeout: 60 * time.Second, } + logger.UtilLog.Infof( + "HTTP2 IdleTimeout=%v", + h2Server.IdleTimeout, + ) server := &http.Server{ Addr: bindAddr, Handler: h2c.NewHandler(handler, h2Server), diff --git a/middleware/3gpp_Sbi_Request_Info.go b/middleware/3gpp_Sbi_Request_Info.go new file mode 100644 index 0000000..e771d3b --- /dev/null +++ b/middleware/3gpp_Sbi_Request_Info.go @@ -0,0 +1,39 @@ +package middleware + +import ( + "net/http" + "sync" + + "github.com/gin-gonic/gin" +) + +var requestCache sync.Map + +func IdempotencyMiddleware() gin.HandlerFunc { + return func(c *gin.Context) { + + if c.Request.Method != http.MethodPost { + c.Next() + return + } + + requestInfo := c.GetHeader("3gpp-Sbi-Request-Info") + + if requestInfo == "" { + c.Next() + return + } + + if _, exists := requestCache.Load(requestInfo); exists { + c.JSON(http.StatusConflict, gin.H{ + "error": "duplicate request detected", + }) + c.Abort() + return + } + + requestCache.Store(requestInfo, true) + + c.Next() + } +} From 27c0fce82aa694efe5c806776b05f44df549a5e3 Mon Sep 17 00:00:00 2001 From: anaswara Date: Thu, 18 Jun 2026 18:43:28 +0530 Subject: [PATCH 2/3] log added --- middleware/3gpp_Sbi_Request_Info.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/middleware/3gpp_Sbi_Request_Info.go b/middleware/3gpp_Sbi_Request_Info.go index e771d3b..90061b1 100644 --- a/middleware/3gpp_Sbi_Request_Info.go +++ b/middleware/3gpp_Sbi_Request_Info.go @@ -4,6 +4,7 @@ import ( "net/http" "sync" + "github.com/5GC-DEV/util-cdac/logger" "github.com/gin-gonic/gin" ) @@ -19,6 +20,15 @@ func IdempotencyMiddleware() gin.HandlerFunc { requestInfo := c.GetHeader("3gpp-Sbi-Request-Info") + if requestInfo != "" { + logger.UtilLog.Infof( + "Received idempotency key=%s method=%s path=%s", + requestInfo, + c.Request.Method, + c.Request.URL.Path, + ) + } + if requestInfo == "" { c.Next() return From bd15f40e3f3482b92db3d3ce059f036bb586a05a Mon Sep 17 00:00:00 2001 From: anaswara Date: Wed, 1 Jul 2026 15:23:14 +0530 Subject: [PATCH 3/3] removed commented code --- drsm/claim.go | 18 ------------------ drsm/drsm.go | 38 -------------------------------------- 2 files changed, 56 deletions(-) diff --git a/drsm/claim.go b/drsm/claim.go index 56c64ee..0d99812 100644 --- a/drsm/claim.go +++ b/drsm/claim.go @@ -10,24 +10,6 @@ import ( "go.mongodb.org/mongo-driver/bson" ) -/*func (d *Drsm) podDownDetected() { - logger.DrsmLog.Infoln("started Pod Down goroutine") - for p := range d.podDown { - logger.DrsmLog.Infof("pod Down detected %v", p) - // Given Pod find out current Chunks owned by this POD - pd := d.podMap[p] - for k := range pd.podChunks { - d.globalChunkTblMutex.Lock() - c, found := d.globalChunkTbl[k] - d.globalChunkTblMutex.Unlock() - logger.DrsmLog.Debugf("found: %v chunk: %v", found, c) - if found { - go c.claimChunk(d, pd.PodId.PodName) - } - } - } -}*/ - func (d *Drsm) podDownDetected() { logger.DrsmLog.Infoln("started Pod Down goroutine") diff --git a/drsm/drsm.go b/drsm/drsm.go index 0387ab0..94ab9fc 100644 --- a/drsm/drsm.go +++ b/drsm/drsm.go @@ -34,13 +34,6 @@ type chunk struct { resourceValidCb func(int32) bool } -/*type podData struct { - PodId PodId `bson:"podId,omitempty" json:"podId,omitempty"` - Timestamp time.Time `bson:"time,omitempty" json:"time,omitempty"` - PrevTimestamp time.Time `bson:"-" json:"-"` - podChunks map[int32]*chunk `bson:"-" json:"-"` // chunkId to Chunk -}*/ - type podData struct { PodId PodId Timestamp time.Time @@ -76,37 +69,6 @@ func (d *Drsm) DeletePod(podInstance string) { logger.DrsmLog.Infoln("deleted PodId from DB:", podInstance) } -/*func (d *Drsm) ConstuctDrsm(opt *Options) { - if opt != nil { - d.mode = opt.Mode - logger.DrsmLog.Debugln("drsm mode set to", d.mode) - if opt.ResIdSize > 0 { - d.resIdSize = opt.ResIdSize - } else { - d.resIdSize = 24 - } - d.resourceValidCb = opt.ResourceValidCb - } - d.chunkIdRange = 1 << (d.resIdSize - 10) - logger.DrsmLog.Debugf("chunkId in the range of 0 to %v", d.chunkIdRange) - d.localChunkTbl = make(map[int32]*chunk) - d.globalChunkTbl = make(map[int32]*chunk) - d.podMap = make(map[string]*podData) - d.podDown = make(chan string, 10) - d.scanChunks = make(map[int32]*chunk) - d.globalChunkTblMutex = sync.Mutex{} - d.initIpam(opt) - - // connect to DB - d.mongo, _ = MongoDBLibrary.NewMongoClient(d.db.Url, d.db.Name) - logger.DrsmLog.Debugln("mongoClient is created", d.db.Name) - - go d.handleDbUpdates() - go d.punchLiveness() - go d.podDownDetected() - go d.checkAllChunks() -}*/ - func (d *Drsm) ConstuctDrsm(opt *Options) { if opt != nil { d.mode = opt.Mode