diff --git a/go-apps/meep-sss/server/meep-sss.go b/go-apps/meep-sss/server/meep-sss.go index bce768a34be8406e5af89cba99f2d60437ef70e0..e3d7134d68541b30abd8952068b7b6175a94e669 100644 --- a/go-apps/meep-sss/server/meep-sss.go +++ b/go-apps/meep-sss/server/meep-sss.go @@ -615,12 +615,17 @@ func startIotPlatformDiscoveryTicker() { continue } log.Debug("startIotPlatformDiscoveryTicker: uri: ", u) + log.Debug("startIotPlatformDiscoveryTicker: host: ", u.Host) - log.Debug("startIotPlatformDiscoveryTicker: port: ", u.Port()) log.Debug("startIotPlatformDiscoveryTicker: path: ", u.Path) log.Debug("startIotPlatformDiscoveryTicker: query: ", u.Query()) log.Debug("startIotPlatformDiscoveryTicker: scheme: ", u.Scheme) log.Debug("startIotPlatformDiscoveryTicker: raw: ", u.RawQuery) + port := u.Port() + u.Host = u.Scheme + "://" + u.Hostname() + log.Debug("startIotPlatformDiscoveryTicker: address: ", u.Host) + log.Debug("startIotPlatformDiscoveryTicker: port: ", port) + // Need to send request...... p = sbi.IotPlatformInfo{ /* For HTTP */ Host: u.Host, @@ -636,9 +641,10 @@ func startIotPlatformDiscoveryTicker() { Protocol: v.UserTransportInfo[0].Protocol, */ } - p.Port, err = strconv.Atoi(u.Port()) + p.Port, err = strconv.Atoi(port) if err != nil { log.Error("startIotPlatformDiscoveryTicker: Port comversion: ", err.Error()) + // if u.Scheme == "https" { p.Port = 443 log.Debug("startIotPlatformDiscoveryTicker: Force port to 443") @@ -1612,11 +1618,11 @@ func isSubscriptionIdRegisteredSensorStatus(subsIdStr string) bool { } /* - * func processSensorDataSubscription(bodyBytes []byte, link *SubscriptionLinks, subsIdStr string, sensorDataSubscription *SensorDataSubscription) (string, error) { - is to create subscription at /subscriptions endpoint - * @param {struct} w HTTP write reference - * @param {struct} r contains the HTTP request - * @see ETSI GS MEC 046 V3.1.1 (2024-04) Clause 7.10.3.4 POST +* func processSensorDataSubscription(bodyBytes []byte, link *SubscriptionLinks, subsIdStr string, sensorDataSubscription *SensorDataSubscription) (string, error) { +is to create subscription at /subscriptions endpoint +* @param {struct} w HTTP write reference +* @param {struct} r contains the HTTP request +* @see ETSI GS MEC 046 V3.1.1 (2024-04) Clause 7.10.3.4 POST */ func processSensorDataSubscription(bodyBytes []byte, link *SubscriptionLinks, subsIdStr string, sensorDataSubscription *SensorDataSubscription) (string, error) { diff --git a/go-packages/meep-sss-mgr/SssMgrBindingProtocol.go b/go-packages/meep-sss-mgr/SssMgrBindingProtocol.go index 8ad55189cfc206ec271a380ee8c627cee430780a..8dfa8560334ed74e8303560348ef7d805ae467fb 100644 --- a/go-packages/meep-sss-mgr/SssMgrBindingProtocol.go +++ b/go-packages/meep-sss-mgr/SssMgrBindingProtocol.go @@ -9,6 +9,7 @@ type SssMgrBindingProtocol interface { type SssMgrBindingProtocolContext struct { host string port int + scheme string path string name string hostId string diff --git a/go-packages/meep-sss-mgr/http.go b/go-packages/meep-sss-mgr/http.go index 909b1edac0e71ae9a925c01e3be8b6a2fe043f2c..881013cd6852b8126cc57e7bd5abd19eb01b9228 100644 --- a/go-packages/meep-sss-mgr/http.go +++ b/go-packages/meep-sss-mgr/http.go @@ -138,14 +138,23 @@ func (http_mgr *SssMgrHttp) send(p_ctx SssMgrBindingProtocolContext) (err error, if to != p_ctx.name && !strings.Contains(to, "/") && p_ctx.name != "" { to = p_ctx.name + "/" + to } - scheme := "https://" - if p_ctx.port != 443 { - scheme = "http://" - } - if p_ctx.path != "" { - url = scheme + p_ctx.host + ":" + strconv.Itoa(p_ctx.port) + "/" + p_ctx.path + "/" + to + scheme := p_ctx.scheme + // if p_ctx.scheme == "https" { + // scheme = "https://" + // } + if p_ctx.path != "" && scheme != "" && p_ctx.host != "" && p_ctx.port != 0 { + if strings.HasPrefix(p_ctx.path, "/") { + p_ctx.path = p_ctx.path[1:len(p_ctx.path)] + } + url = scheme + "://" + p_ctx.host + ":" + strconv.Itoa(p_ctx.port) + "/" + p_ctx.path + "/" + to + } else if scheme != "" && p_ctx.host != "" && p_ctx.port != 0 { + url = scheme + "://" + p_ctx.host + ":" + strconv.Itoa(p_ctx.port) + "/" + to + } else if p_ctx.host != "" && p_ctx.port != 0 { + url = p_ctx.host + ":" + strconv.Itoa(p_ctx.port) + "/" + to } else { - url = scheme + p_ctx.host + ":" + strconv.Itoa(p_ctx.port) + "/" + to + err := errors.New("Invalid p_ctx") + log.Error("send: ", err.Error()) + return err, nil } // Set the method method := "" @@ -203,6 +212,7 @@ func sendRequest(method string, url string, headers http.Header, body io.Reader, log.Debug(">>> sendRequest: url: ", url) log.Debug(">>> sendRequest: headers: ", headers) + // var bodyBytes []byte var err error if body != nil { @@ -265,7 +275,7 @@ func sendRequest(method string, url string, headers http.Header, body io.Reader, log.Debug("sendRequest: rr: ", rr) log.Debug("sendRequest: rr.Body: ", rr.Body) } - + status := rr.StatusCode if status == 502 || status == 503 { log.Debug("sendRequest: attempt ", attempt+1, " received status ", status) @@ -277,7 +287,7 @@ func sendRequest(method string, url string, headers http.Header, body io.Reader, } continue } - + if status != code { responseData, _ := ioutil.ReadAll(rr.Body) rr.Body.Close() diff --git a/go-packages/meep-sss-mgr/onem2m-mgr.go b/go-packages/meep-sss-mgr/onem2m-mgr.go index db9c741f973b16f8351378e47a68173aed1a699d..9c2d49436f1774eff8886a4e56c2f3341175e723 100644 --- a/go-packages/meep-sss-mgr/onem2m-mgr.go +++ b/go-packages/meep-sss-mgr/onem2m-mgr.go @@ -26,6 +26,7 @@ import ( "strings" "sync" "time" + // "net" log "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-logger" @@ -40,6 +41,7 @@ type SssMgr struct { protocol SssMgrBindingProtocol host string port int + scheme string path string cse_name string hostId string @@ -214,6 +216,7 @@ func NewSssMgr_with_uri(name string, namespace string, bindingProtocol string, u tm.host = u.Hostname() tm.port, err = strconv.Atoi(u.Port()) tm.path = u.Path + tm.scheme = u.Scheme if err != nil { tm.port = 443 log.Debug("NewSssMgr_with_uri: Force port to ", tm.port) @@ -391,6 +394,7 @@ func (tm *SssMgr) GetSensor(sensorIdentifier string) (sensor SensorDiscoveryInfo */ func (tm *SssMgr) populateDevicesPerIotPlatforms() error { + log.Debug(">>> populateDevicesPerIotPlatforms (go-packages/meep-sss-mgr/onem2m-mgr.go)") if profiling { profilingTimers["populateDevicesPerIotPlatforms"] = time.Now() } @@ -401,6 +405,20 @@ func (tm *SssMgr) populateDevicesPerIotPlatforms() error { // Refresh the list of devices for all registered Iot platform for _, iotPlatform := range registeredIotPlatformsMap { + // address := iotPlatform.Address + // if iotPlatform.Port != 0 { + // if host, _, err := net.SplitHostPort(address); err == nil { + // address = host + // } + // } + // if !strings.HasPrefix(address, "mqtt") && + // !strings.HasPrefix(address, "wss") && + // !strings.HasPrefix(address, "http://") && + // !strings.HasPrefix(address, "https://") { + // address = tm.scheme + "://" + address + // } + // log.Debug("populateDevicesPerIotPlatforms: processing: ", tm.scheme) + // iotPlatform.Address = address log.Debug("populateDevicesPerIotPlatforms: processing: ", iotPlatform.Address) err := tm.populateSensors(iotPlatform, "3") if err != nil { @@ -446,6 +464,7 @@ func (tm *SssMgr) populateSensors(iotPlatformInfo IotPlatformInfo, type_ string) host: iotPlatformInfo.Address, port: iotPlatformInfo.Port, path: tm.path, + scheme: tm.scheme, name: iotPlatformInfo.Name, hostId: iotPlatformInfo.IotPlatformId, to: iotPlatformInfo.Name, @@ -669,6 +688,7 @@ func (tm *SssMgr) OneM2M_create(sensor SensorDiscoveryInfo, path string, origina host: registeredIotPlatformsMap[sensor.IotPlatformId].Address, port: registeredIotPlatformsMap[sensor.IotPlatformId].Port, path: tm.path, + scheme: tm.scheme, name: registeredIotPlatformsMap[sensor.IotPlatformId].Name, hostId: sensor.IotPlatformId, to: registeredIotPlatformsMap[sensor.IotPlatformId].Name, @@ -778,6 +798,7 @@ func (tm *SssMgr) OneM2M_discovery(type_ string, iotPlatformId string, originato host: registeredIotPlatformsMap[iotPlatformId].Address, port: registeredIotPlatformsMap[iotPlatformId].Port, path: tm.path, + scheme: tm.scheme, name: registeredIotPlatformsMap[iotPlatformId].Name, hostId: iotPlatformId, to: registeredIotPlatformsMap[iotPlatformId].Name, @@ -871,6 +892,7 @@ func (tm *SssMgr) OneM2M_get(path string, iotPlatformId string, originator strin host: registeredIotPlatformsMap[iotPlatformId].Address, port: registeredIotPlatformsMap[iotPlatformId].Port, path: tm.path, + scheme: tm.scheme, name: registeredIotPlatformsMap[iotPlatformId].Name, hostId: iotPlatformId, to: path, @@ -935,6 +957,7 @@ func (tm *SssMgr) OneM2M_subscribe(iotPlatformId string, path string, originator host: registeredIotPlatformsMap[iotPlatformId].Address, port: registeredIotPlatformsMap[iotPlatformId].Port, path: tm.path, + scheme: tm.scheme, name: registeredIotPlatformsMap[iotPlatformId].Name, hostId: iotPlatformId, to: path, @@ -1040,6 +1063,7 @@ func (tm *SssMgr) OneM2M_delete(sensor SensorDiscoveryInfo, originator string) ( host: registeredIotPlatformsMap[sensor.IotPlatformId].Address, port: registeredIotPlatformsMap[sensor.IotPlatformId].Port, path: tm.path, + scheme: tm.scheme, name: registeredIotPlatformsMap[sensor.IotPlatformId].Name, hostId: sensor.IotPlatformId, to: sensor.SensorIdentifier, @@ -1092,6 +1116,7 @@ func (tm *SssMgr) OneM2M_delete_subscription(subId string, originator string) (e host: registeredIotPlatformsMap[subscriptionListPerSubId[subId].IotPlatformId].Address, port: registeredIotPlatformsMap[subscriptionListPerSubId[subId].IotPlatformId].Port, path: tm.path, + scheme: tm.scheme, name: registeredIotPlatformsMap[subscriptionListPerSubId[subId].IotPlatformId].Name, hostId: subscriptionListPerSubId[subId].IotPlatformId, to: subscriptionListPerSubId[subId].SensorIdentifier,