From 83ff7b4eba8a20071085497d8322edb201645a4f Mon Sep 17 00:00:00 2001 From: Thomas Quandalle Date: Tue, 21 Jun 2022 11:46:54 +0200 Subject: [PATCH] add heartbeating --- machinery/data/config/config.json | 7 +- machinery/go.mod | 13 +- machinery/go.sum | 37 ++- machinery/src/cloud/Cloud.go | 281 ++++++++++++++++++ machinery/src/cloud/KerberosVault.go | 96 ++++++ machinery/src/cloud/S3.go | 118 ++++++++ machinery/src/components/IPCamera.go | 5 +- machinery/src/components/Kerberos.go | 33 +- .../main.go} | 2 +- machinery/src/models/Communication.go | 2 + .../{components/Utils.go => utils/main.go} | 2 +- 11 files changed, 577 insertions(+), 19 deletions(-) create mode 100644 machinery/src/cloud/Cloud.go create mode 100644 machinery/src/cloud/KerberosVault.go create mode 100644 machinery/src/cloud/S3.go rename machinery/src/{components/ImageProcessing.go => computervision/main.go} (99%) rename machinery/src/{components/Utils.go => utils/main.go} (98%) diff --git a/machinery/data/config/config.json b/machinery/data/config/config.json index ae5e7f0..f47b511 100644 --- a/machinery/data/config/config.json +++ b/machinery/data/config/config.json @@ -10,7 +10,6 @@ "turnuri": "turn:turn.kerberos.io:8443", "turn_username": "username1", "turn_password": "password1", - "heartbeaturi": "https://api.cloud.kerberos.io/devices/heartbeat", "capture": { "id": "ipcamera", "ipcamera": { @@ -89,11 +88,15 @@ "polygon": [] }, "cloud": "kstorage", + "hub_uri": "https://api.cloud.kerberos.io", + "hub_key": "AKIA5V6EGLUWUUWHY3QB", + "hub_private_key": "pH/pfQhZ7c2jbBqnFBEGE1Z86VDaS8uGjF7bSC/6", + "hub_site": "", "kstorage": { "uri": "https://staging.api.vault.kerberos.live", "access_key": "ABCDEFGHI!@#$%12345", "secret_access_key": "JKLMNOPQRSTUVWXYZ!@#$%67890", "provider": "", - "directory": "youruser" + "directory": "cedricve" } } diff --git a/machinery/go.mod b/machinery/go.mod index 2a40b8f..d076558 100644 --- a/machinery/go.mod +++ b/machinery/go.mod @@ -15,8 +15,10 @@ require ( github.com/golang-jwt/jwt/v4 v4.2.0 github.com/kellydunn/golang-geo v0.7.0 github.com/kerberos-io/joy4 v1.0.32 + github.com/minio/minio-go/v6 v6.0.57 github.com/op/go-logging v0.0.0-20160315200505-970db520ece7 github.com/pion/webrtc/v3 v3.1.41 + github.com/shirou/gopsutil v3.21.11+incompatible github.com/sirupsen/logrus v1.8.1 github.com/swaggo/files v0.0.0-20220610200504-28940afbdbfe github.com/swaggo/gin-swagger v1.5.0 @@ -33,6 +35,7 @@ require ( github.com/clbanning/mxj v1.8.4 // indirect github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5 // indirect github.com/gin-contrib/sse v0.1.0 // indirect + github.com/go-ole/go-ole v1.2.6 // indirect github.com/go-openapi/jsonpointer v0.19.5 // indirect github.com/go-openapi/jsonreference v0.19.6 // indirect github.com/go-openapi/spec v0.20.4 // indirect @@ -46,11 +49,15 @@ require ( github.com/gorilla/websocket v1.4.2 // indirect github.com/josharian/intern v1.0.0 // indirect github.com/json-iterator/go v1.1.12 // indirect + github.com/klauspost/cpuid v1.2.3 // indirect github.com/kylelemons/go-gypsy v1.0.0 // indirect github.com/leodido/go-urn v1.2.1 // indirect github.com/lib/pq v1.10.6 // indirect github.com/mailru/easyjson v0.7.6 // indirect github.com/mattn/go-isatty v0.0.14 // indirect + github.com/minio/md5-simd v1.1.0 // indirect + github.com/minio/sha256-simd v0.1.1 // indirect + github.com/mitchellh/go-homedir v1.1.0 // indirect github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect github.com/modern-go/reflect2 v1.0.2 // indirect github.com/pelletier/go-toml/v2 v2.0.1 // indirect @@ -70,14 +77,18 @@ require ( github.com/pion/transport v0.13.0 // indirect github.com/pion/turn/v2 v2.0.8 // indirect github.com/pion/udp v0.1.1 // indirect + github.com/tklauser/go-sysconf v0.3.10 // indirect + github.com/tklauser/numcpus v0.4.0 // indirect github.com/ugorji/go/codec v1.2.7 // indirect + github.com/yusufpapurcu/wmi v1.2.2 // indirect github.com/ziutek/mymysql v1.5.4 // indirect golang.org/x/crypto v0.0.0-20220516162934-403b01795ae8 // indirect golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 // indirect golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect - golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e // indirect + golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27 // indirect golang.org/x/text v0.3.7 // indirect golang.org/x/tools v0.1.10 // indirect google.golang.org/protobuf v1.28.0 // indirect + gopkg.in/ini.v1 v1.42.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect ) diff --git a/machinery/go.sum b/machinery/go.sum index 02d40d6..37bce7d 100644 --- a/machinery/go.sum +++ b/machinery/go.sum @@ -25,6 +25,7 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/deepch/vdk v0.0.17 h1:FbNgJ3DVHRuMoVCUFcKAwAQ+EBfgP8nygVbg+fiqUAY= github.com/deepch/vdk v0.0.17/go.mod h1:KqQ/KU3hOc4a62l/jPRH5Hiz5fhTq5cGCl8IqeCxWQI= +github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/eclipse/paho.mqtt.golang v1.4.1 h1:tUSpviiL5G3P9SZZJPC4ZULZJsxQKXxfENpMvdbAXAI= github.com/eclipse/paho.mqtt.golang v1.4.1/go.mod h1:JGt0RsEwEX+Xa/agj90YJ9d9DH2b7upDZMK9HRbFvCA= github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5 h1:Yzb9+7DPaBjB8zlTR87/ElzFsnQfuHnVUVqpZZIcV5Y= @@ -48,6 +49,8 @@ github.com/gin-gonic/gin v1.7.4/go.mod h1:jD2toBW3GZUr5UMcdrwQA10I7RuaFOl/SGeDjX github.com/gin-gonic/gin v1.7.7/go.mod h1:axIBovoeJpVj8S3BwE0uPMTeReE4+AfFtqpqaZ1qq1U= github.com/gin-gonic/gin v1.8.1 h1:4+fr/el88TOO3ewCmQr8cx/CtZ/umlIRIs5M4NTNjf8= github.com/gin-gonic/gin v1.8.1/go.mod h1:ji8BvRH1azfM+SYow9zQ6SZMvR8qOMZHmsCuWR9tTTk= +github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY= +github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= github.com/go-openapi/jsonpointer v0.19.5 h1:gZr+CIYByUqjcgeLXnQu2gHYQC9o73G2XUeOFYEICuY= github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= @@ -100,6 +103,7 @@ github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/ github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc= github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= @@ -111,11 +115,15 @@ github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/u github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= +github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/kellydunn/golang-geo v0.7.0 h1:A5j0/BvNgGwY6Yb6inXQxzYwlPHc6WVZR+MrarZYNNg= github.com/kellydunn/golang-geo v0.7.0/go.mod h1:YYlQPJ+DPEzrHx8kT3oPHC/NjyvCCXE+IuKGKdrjrcU= github.com/kerberos-io/joy4 v1.0.32 h1:rQcMEnc9sDpbRj4sh5+X807yPEhhKDa8gKUCJKMhJ5k= github.com/kerberos-io/joy4 v1.0.32/go.mod h1:nZp4AjvKvTOXRrmDyAIOw+Da+JA5OcSo/JundGfOlFU= +github.com/klauspost/cpuid v1.2.3 h1:CCtW0xUnWGVINKvE/WWOYKdsPV6mawAtvQuSl8guwQs= +github.com/klauspost/cpuid v1.2.3/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek= +github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= @@ -142,6 +150,14 @@ github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2y github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= +github.com/minio/md5-simd v1.1.0 h1:QPfiOqlZH+Cj9teu0t9b1nTBfPbyTl16Of5MeuShdK4= +github.com/minio/md5-simd v1.1.0/go.mod h1:XpBqgZULrMYD3R+M28PcmP0CkI7PEMzB3U77ZrKZ0Gw= +github.com/minio/minio-go/v6 v6.0.57 h1:ixPkbKkyD7IhnluRgQpGSpHdpvNVaW6OD5R9IAO/9Tw= +github.com/minio/minio-go/v6 v6.0.57/go.mod h1:5+R/nM9Pwrh0vqF+HbYYDQ84wdUFPyXHkrdT4AIkifM= +github.com/minio/sha256-simd v0.1.1 h1:5QHSlgo3nt5yKOJrC7W8w7X+NFl8cMPZm96iu8kKUJU= +github.com/minio/sha256-simd v0.1.1/go.mod h1:B5e1o+1/KgNmWrSQK08Y6Z1Vb5pwIktudl0J58iy0KM= +github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= +github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= @@ -235,10 +251,16 @@ github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUA github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/sclevine/agouti v3.0.0+incompatible/go.mod h1:b4WX9W9L1sfQKXeJf1mUTLZKJ48R1S7H23Ji7oFO5Bw= +github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI= +github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= +github.com/sirupsen/logrus v1.5.0/go.mod h1:+F7Ogzej0PZc/94MaYx/nvG9jOFMD2osvC3s+Squfpo= github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE= github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= +github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= +github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= +github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s= github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= @@ -262,6 +284,10 @@ github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs= github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= +github.com/tklauser/go-sysconf v0.3.10 h1:IJ1AZGZRWbY8T5Vfk04D9WOA5WSejdflXxP03OUqALw= +github.com/tklauser/go-sysconf v0.3.10/go.mod h1:C8XykCvCb+Gn0oNCWPIlcb0RuglQTYaQ2hGm7jmxEFk= +github.com/tklauser/numcpus v0.4.0 h1:E53Dm1HjH1/R2/aoCtXtPgzmElmn51aOkhCFSuZq//o= +github.com/tklauser/numcpus v0.4.0/go.mod h1:1+UI3pD8NW14VMwdgJNJ1ESk2UnwhAnz5hMwiKKqXCQ= github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= github.com/ugorji/go v1.2.7/go.mod h1:nF9osbDWLy6bDVv/Rtoh6QgnvNDpmCalQV5urGCCS6M= github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY= @@ -270,12 +296,15 @@ github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95 github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= +github.com/yusufpapurcu/wmi v1.2.2 h1:KBNDSne4vP5mbSWnJbO+51IMOXJB67QiYCSBrubbPRg= +github.com/yusufpapurcu/wmi v1.2.2/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= github.com/ziutek/mymysql v1.5.4 h1:GB0qdRGsTwQSBVYuVShFBKaXSnSnYYC2d9knnE1LHFs= github.com/ziutek/mymysql v1.5.4/go.mod h1:LMSpPZ6DbqWFxNCHW77HeMg9I646SAhApZ/wKdgO/C0= gocv.io/x/gocv v0.31.0 h1:BHDtK8v+YPvoSPQTTiZB2fM/7BLg6511JqkruY2z6LQ= gocv.io/x/gocv v0.31.0/go.mod h1:oc6FvfYqfBp99p+yOEzs9tbYF9gOrAQSeL/dyIPefJU= golang.org/x/crypto v0.0.0-20190228161510-8dd112bcdc25/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200602180216-279210d13fed/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= @@ -291,6 +320,7 @@ golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 h1:kQgndtyPBW/JIYERgdx golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20191126235420-ef20fe5d7933/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= @@ -321,8 +351,10 @@ golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190228124157-a34e9553db1e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -338,8 +370,9 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e h1:fLOSk5Q00efkSvAm+4xcoXD+RRmLmmulPn5I3Y9F2EM= golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27 h1:XDXtA5hveEEV8JB2l7nhMTp3t3cHp9ZpwcdjqyEWLlo= +golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -380,6 +413,8 @@ gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE= gopkg.in/go-playground/validator.v9 v9.29.1/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWdVbfP1avr/N00E2vyQ= +gopkg.in/ini.v1 v1.42.0 h1:7N3gPTt50s8GuLortA00n8AqRTk75qOP98+mTPpgzRk= +gopkg.in/ini.v1 v1.42.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22 h1:VpOs+IwYnYBaFnrNAeB8UUWtL3vEUnzSCL1nVjPhqrw= gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22/go.mod h1:yeKp02qBN3iKW1OzL3MGk2IdtZzaj7SFntXj72NppTA= gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXLknAOE8= diff --git a/machinery/src/cloud/Cloud.go b/machinery/src/cloud/Cloud.go new file mode 100644 index 0000000..b0d9a14 --- /dev/null +++ b/machinery/src/cloud/Cloud.go @@ -0,0 +1,281 @@ +package cloud + +import ( + "bytes" + "encoding/base64" + "fmt" + "sync" + + "github.com/kerberos-io/joy4/av/pubsub" + + mqtt "github.com/eclipse/paho.mqtt.golang" + av "github.com/kerberos-io/joy4/av" + "github.com/kerberos-io/joy4/cgo/ffmpeg" + "gocv.io/x/gocv" + + "net/http" + "runtime" + "runtime/debug" + "strconv" + "time" + + "github.com/kerberos-io/agent/machinery/src/computervision" + "github.com/kerberos-io/agent/machinery/src/log" + "github.com/kerberos-io/agent/machinery/src/models" + "github.com/kerberos-io/agent/machinery/src/utils" + "github.com/shirou/gopsutil/disk" + "github.com/shirou/gopsutil/host" +) + +func PendingUpload() { + ff, err := utils.ReadDirectory("./data/cloud/") + if err == nil { + for _, f := range ff { + log.Log.Info(f.Name()) + } + } +} + +func StartUpload(configuration *models.Configuration, communication *models.Communication) { + + config := configuration.Config + watchDirectory := "./data/cloud/" + +loop: + for { + ff, err := utils.ReadDirectory(watchDirectory) + + // This will check if we need to stop the thread, + // because of a reconfiguration. + select { + case <-communication.HandleUpload: + break loop + default: + } + + if err == nil { + for _, f := range ff { + + // This will check if we need to stop the thread, + // because of a reconfiguration. + select { + case <-communication.HandleUpload: + break loop + default: + } + + fileName := f.Name() + if config.Cloud == "s3" { + UploadS3(configuration, fileName, watchDirectory) + } else if config.Cloud == "kstorage" { + UploadKerberosVault(configuration, fileName, watchDirectory) + } + } + } + time.Sleep(1 * time.Second) + } +} + +func HandleHeartBeat(configuration *models.Configuration, communication *models.Communication) { + + log.Log.Debug("HandleHeartBeat: started") + + config := configuration.Config + + url := config.HeartbeatURI + key := "" + username := "" + vaultURI := "" + + if config.Cloud == "s3" && config.S3.Publickey != "" { + username = config.S3.Username + key = config.S3.Publickey + } else if config.Cloud == "kstorage" && config.KStorage.CloudKey != "" { + key = config.KStorage.CloudKey + username = config.KStorage.Directory + vaultURI = config.KStorage.URI + } + + // This is the new way ;) + if config.HubURI != "" { + url = config.HubURI + "/devices/heartbeat" + } + if config.HubKey != "" { + key = config.HubKey + } + +loop: + for { + // This will check if we need to stop the thread, + // because of a reconfiguration. + select { + case <-communication.HandleHeartBeat: + break loop + default: + } + + uptime, _ := host.Uptime() + days := strconv.Itoa(int(uptime / (60 * 60 * 24))) + //12:11:48 up 11 days + + //partitions, _ := disk.Partitions(false) + usage, _ := disk.Usage("/") + diskPercentUsed := strconv.Itoa(int(usage.UsedPercent)) + + onvifEnabled := "false" + if config.Capture.IPCamera.ONVIFXAddr != "" { + onvifEnabled = "true" + } + + var object = fmt.Sprintf(`{ + "key" : "%s", + "hash" : "826133658", + "version" : "3.0.0", + "cpuid" : "Serial: 00000000d71d1e62", + "clouduser" : "%s", + "cloudpublickey" : "%s", + "cameraname" : "%s", + "cameratype" : "IPCamera", + "docker" : true, + "kios" : false, + "raspberrypi" : false, + "enterprise" : true, + "board" : "", + "disk1size" : "%s", + "disk3size" : "%s", + "diskvdasize" : "%s", + "numberoffiles" : "33", + "temperature" : "sh: 1: vcgencmd: not found", + "wifissid" : "", + "wifistrength" : "", + "uptime" : "up %s days,", + "timestamp" : 1564747908, + "siteID" : "%s", + "onvif" : "%s" + }`, config.Key, username, key, config.Name, "0", "0", diskPercentUsed, days, config.HubSite, onvifEnabled) + + var jsonStr = []byte(object) + buffy := bytes.NewBuffer(jsonStr) + req, _ := http.NewRequest("POST", url, buffy) + req.Header.Set("Content-Type", "application/json") + + client := &http.Client{} + resp, err := client.Do(req) + if resp != nil { + resp.Body.Close() + } + if err == nil && resp.StatusCode == 200 { + log.Log.Info("HandleHeartBeat: (200) Heartbeat received by Kerberos Hub.") + } else { + log.Log.Error("HandleHeartBeat: (400) Something went wrong while sending to Kerberos Hub.") + } + + // If we have a vault connect, we will also send some analytics + // to that service. + if vaultURI != "" { + buffy = bytes.NewBuffer(jsonStr) + req, _ = http.NewRequest("POST", vaultURI+"/devices/heartbeat", buffy) + req.Header.Set("Content-Type", "application/json") + + client = &http.Client{} + resp, err = client.Do(req) + if resp != nil { + resp.Body.Close() + } + if err == nil && resp.StatusCode == 200 { + log.Log.Info("HandleHeartBeat: (200) Heartbeat received by Kerberos Vault.") + } else { + log.Log.Error("HandleHeartBeat: (400) Something went wrong while sending to Kerberos Vault.") + } + } + + time.Sleep(30 * time.Second) + } + + log.Log.Debug("HandleHeartBeat: finished") +} + +func SendLiveStream(configuration *models.Configuration, livestreamChan chan int64, livestreamCursor *pubsub.QueueCursor, decoder *ffmpeg.VideoDecoder, decoderMutex *sync.Mutex) { + config := configuration.Config + key := "" + if config.Cloud == "s3" && config.S3.Publickey != "" { + key = config.S3.Publickey + } else if config.Cloud == "kstorage" && config.KStorage.CloudKey != "" { + key = config.KStorage.CloudKey + } + // This is the new way ;) + if config.HubKey != "" { + key = config.HubKey + } + + topic := "kerberos/" + key + "/device/" + config.Key + "/live" + + lastLivestreamRequest := int64(0) + + //for pkt := range packets { + var cursorError error + var pkt av.Packet + + for cursorError == nil { + + pkt, cursorError = livestreamCursor.ReadPacket() + + if len(pkt.Data) == 0 || !pkt.IsKeyFrame { + continue + } + now := time.Now().Unix() + select { + case <-livestreamChan: + lastLivestreamRequest = now + default: + } + if now-lastLivestreamRequest > 3 { + continue + } + log.Log.Info("Livestream: sending base64 encoded images to cloud.") + //sendImage(topic, mqc, pkt, decoder, decoderMutex) + log.Log.Info(topic) + } +} + +func sendImage(topic string, mqc mqtt.Client, pkt av.Packet, decoder *ffmpeg.VideoDecoder, decoderMutex *sync.Mutex) { + mat := computervision.GetRGBImage(pkt, decoder, decoderMutex) + buffer, err := gocv.IMEncode(gocv.JPEGFileExt, mat) + mat.Close() + if err == nil { + encoded := base64.StdEncoding.EncodeToString(buffer.GetBytes()) + mqc.Publish(topic, 0, false, encoded) + } + runtime.GC() + debug.FreeOSMemory() +} + +/*func SendWebRTCStream(config components.Config, livestreamCursor *pubsub.QueueCursor, packets chan av.Packet, mqc mqtt.Client, codecs []av.CodecData, log components.Logging, webrtcChan chan components.SDPPayload, webrtcKeepAlive chan string, webrtcPeers chan string, decoder *ffmpeg.VideoDecoder, decoderMutex *sync.Mutex) { + + // Should create a track here. + track := components.NewVideoTrack() + go components.WriteToTrack(config.Key, webrtcKeepAlive, webrtcPeers, config.Capture.ForwardWebRTC, config.Capture.TranscodingWebRTC, config.Capture.TranscodingResolution, log, track, livestreamCursor, packets, codecs, mqc, decoder, decoderMutex) + + if config.Capture.ForwardWebRTC == "true" { + // We get a request with an offer, but we'll forward it. + for m := range webrtcChan { + // Forward SDP + m.CloudKey = config.Key + request, err := json.Marshal(m) + if err == nil { + mqc.Publish("kerberos/webrtc/request", 2, false, request) + } + } + } else { + log.Info("WebRTC (Direct): Waiting for peer connections.") + for m := range webrtcChan { + log.Info("WebRTC (Direct): setting up a peer connection.") + key := config.Key + "/" + m.Cuuid + _, ok := components.CandidateArrays[key] + if !ok { + components.CandidateArrays[key] = make(chan string, 30) + } + components.InitializeWebRTCConnection(track, config, m, mqc, log, components.CandidateArrays[key]) + } + } +}*/ diff --git a/machinery/src/cloud/KerberosVault.go b/machinery/src/cloud/KerberosVault.go new file mode 100644 index 0000000..810a33f --- /dev/null +++ b/machinery/src/cloud/KerberosVault.go @@ -0,0 +1,96 @@ +package cloud + +import ( + "io/ioutil" + "net/http" + "os" + + "github.com/kerberos-io/agent/machinery/src/log" + "github.com/kerberos-io/agent/machinery/src/models" +) + +func UploadKerberosVault(configuration *models.Configuration, fileName string, directory string) bool { + + config := configuration.Config + + if config.KStorage.AccessKey == "" || + config.KStorage.SecretAccessKey == "" || + config.KStorage.Provider == "" || + config.KStorage.Directory == "" || + config.KStorage.URI == "" { + log.Log.Info("Kerberos Vault: not properly configured.") + } + + //fmt.Println("Uploading...") + // timestamp_microseconds_instanceName_regionCoordinates_numberOfChanges_token + // 1564859471_6-474162_oprit_577-283-727-375_1153_27.mp4 + // - Timestamp + // - Size + - + microseconds + // - device + // - Region + // - Number of changes + // - Token + + // KerberosCloud, this means storage is disabled and proxy enabled. + log.Log.Info("Uploading to Kerberos Vault") + + log.Log.Info("Upload started for: " + fileName) + fullname := "data/recordings/" + fileName + + file, err := os.OpenFile(fullname, os.O_RDWR, 0755) + defer file.Close() + if err != nil { + log.Log.Info("Upload Failed: file doesn't exists anymore.") + os.Remove(directory + "/" + fileName) + return false + } + + publicKey := config.KStorage.CloudKey + // This is the new way ;) + if config.HubKey != "" { + publicKey = config.HubKey + } + + log.Log.Info(config.KStorage.URI) + req, err := http.NewRequest("POST", config.KStorage.URI+"/storage", file) + if err != nil { + log.Log.Error("Error reading request. " + err.Error()) + } + req.Header.Set("Content-Type", "video/mp4") + req.Header.Set("X-Kerberos-Storage-CloudKey", publicKey) + req.Header.Set("X-Kerberos-Storage-AccessKey", config.KStorage.AccessKey) + req.Header.Set("X-Kerberos-Storage-SecretAccessKey", config.KStorage.SecretAccessKey) + req.Header.Set("X-Kerberos-Storage-Provider", config.KStorage.Provider) + req.Header.Set("X-Kerberos-Storage-FileName", fileName) + req.Header.Set("X-Kerberos-Storage-Device", config.Key) + req.Header.Set("X-Kerberos-Storage-Capture", "IPCamera") + req.Header.Set("X-Kerberos-Storage-Directory", config.KStorage.Directory) + //client := &http.Client{Timeout: time.Second * 30} + client := &http.Client{} + + resp, err := client.Do(req) + + if resp != nil { + defer resp.Body.Close() + } + + if err == nil { + if resp != nil { + body, err := ioutil.ReadAll(resp.Body) + if err == nil { + if resp.StatusCode == 200 { + log.Log.Info("Upload Finished: " + resp.Status + ", " + string(body)) + // We will remove the file from disk as well + os.Remove(fullname) + os.Remove(directory + "/" + fileName) + } else { + log.Log.Info("Upload Failed: " + resp.Status + ", " + string(body)) + } + resp.Body.Close() + } + } + } else { + log.Log.Info("Upload Failed: " + err.Error()) + } + return true +} diff --git a/machinery/src/cloud/S3.go b/machinery/src/cloud/S3.go new file mode 100644 index 0000000..206d4b4 --- /dev/null +++ b/machinery/src/cloud/S3.go @@ -0,0 +1,118 @@ +package cloud + +import ( + "crypto/tls" + "net/http" + "net/url" + "os" + "strconv" + "strings" + + "github.com/kerberos-io/agent/machinery/src/log" + "github.com/kerberos-io/agent/machinery/src/models" + "github.com/minio/minio-go/v6" +) + +func UploadS3(configuration *models.Configuration, fileName string, directory string) bool { + + config := configuration.Config + + //fmt.Println("Uploading...") + // timestamp_microseconds_instanceName_regionCoordinates_numberOfChanges_token + // 1564859471_6-474162_oprit_577-283-727-375_1153_27.mp4 + // - Timestamp + // - Size + - + microseconds + // - device + // - Region + // - Number of changes + // - Token + + aws_access_key_id := config.S3.Publickey + aws_secret_access_key := config.S3.Secretkey + aws_region := config.S3.Region + + // This is the new way ;) + if config.HubKey != "" { + aws_access_key_id = config.HubKey + } + if config.HubPrivateKey != "" { + aws_secret_access_key = config.HubPrivateKey + } + + s3Client, err := minio.NewWithRegion("s3.amazonaws.com", aws_access_key_id, aws_secret_access_key, true, aws_region) + if err != nil { + log.Log.Error(err.Error()) + } + + // Check if we need to use the proxy. + if config.S3.ProxyURI != "" { + var transport http.RoundTripper = &http.Transport{ + Proxy: func(*http.Request) (*url.URL, error) { + return url.Parse(config.S3.ProxyURI) + }, + TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, + } + s3Client.SetCustomTransport(transport) + } + + fileParts := strings.Split(fileName, "_") + if len(fileParts) == 1 { + log.Log.Error("ERROR: " + fileName + " is not a valid name.") + os.Remove(directory + "/" + fileName) + return false + } + + deviceKey := config.Key + startRecording, _ := strconv.ParseInt(fileParts[0], 10, 64) + devicename := fileParts[2] + coordinates := fileParts[3] + //numberOfChanges := fileParts[4] + token, _ := strconv.Atoi(fileParts[5]) + + log.Log.Info("Upload started for: " + fileName) + fullname := "data/recordings/" + fileName + + file, err := os.OpenFile(fullname, os.O_RDWR, 0755) + defer file.Close() + if err != nil { + log.Log.Error("ERROR: " + err.Error()) + os.Remove(directory + "/" + fileName) + return false + } + + fileInfo, err := file.Stat() + if err != nil { + log.Log.Error("ERROR: " + err.Error()) + os.Remove(directory + "/" + fileName) + return false + } + + n, err := s3Client.PutObject(config.S3.Bucket, + config.S3.Username+"/"+fileName, + file, + fileInfo.Size(), + minio.PutObjectOptions{ + ContentType: "video/mp4", + StorageClass: "ONEZONE_IA", + UserMetadata: map[string]string{ + "event-timestamp": strconv.FormatInt(startRecording, 10), + "event-microseconds": deviceKey, + "event-instancename": devicename, + "event-regioncoordinates": coordinates, + "event-numberofchanges": deviceKey, + "event-token": strconv.Itoa(token), + "productid": deviceKey, + "publickey": aws_access_key_id, + "uploadtime": "now", + }, + }) + + if err != nil { + log.Log.Error("Uploading Failed: " + err.Error()) + return false + } else { + log.Log.Info("Upload Finished: file has been uploaded to bucket: " + strconv.FormatInt(n, 10)) + os.Remove(directory + "/" + fileName) + return true + } +} diff --git a/machinery/src/components/IPCamera.go b/machinery/src/components/IPCamera.go index 5cb201e..36fd6aa 100644 --- a/machinery/src/components/IPCamera.go +++ b/machinery/src/components/IPCamera.go @@ -9,6 +9,7 @@ import ( "github.com/kerberos-io/agent/machinery/src/log" "github.com/kerberos-io/agent/machinery/src/models" + "github.com/kerberos-io/agent/machinery/src/utils" "github.com/kerberos-io/joy4/av/pubsub" "github.com/kerberos-io/joy4/format/mp4" @@ -169,7 +170,7 @@ func RecordStream(recordingCursor *pubsub.QueueCursor, motion chan int64, device // Check if need to convert to fragmented using bento if config.Capture.Fragmented == "true" && config.Capture.FragmentedDuration > 0 { - CreateFragmentedMP4(fullName, config.Capture.FragmentedDuration) + utils.CreateFragmentedMP4(fullName, config.Capture.FragmentedDuration) } // Create a symbol link. @@ -339,7 +340,7 @@ func RecordStream(recordingCursor *pubsub.QueueCursor, motion chan int64, device // Check if need to convert to fragmented using bento if config.Capture.Fragmented == "true" && config.Capture.FragmentedDuration > 0 { - CreateFragmentedMP4(fullName, config.Capture.FragmentedDuration) + utils.CreateFragmentedMP4(fullName, config.Capture.FragmentedDuration) } // Create a symbol linc. diff --git a/machinery/src/components/Kerberos.go b/machinery/src/components/Kerberos.go index 7e2477d..af5a947 100644 --- a/machinery/src/components/Kerberos.go +++ b/machinery/src/components/Kerberos.go @@ -6,6 +6,8 @@ import ( "sync/atomic" "time" + "github.com/kerberos-io/agent/machinery/src/cloud" + "github.com/kerberos-io/agent/machinery/src/computervision" "github.com/kerberos-io/agent/machinery/src/log" "github.com/kerberos-io/agent/machinery/src/models" "github.com/kerberos-io/joy4/av/pubsub" @@ -21,6 +23,7 @@ func Bootstrap(configuration *models.Configuration, communication *models.Commun communication.PackageCounter = &packageCounter communication.HandleStream = make(chan string, 1) communication.HandleMotion = make(chan string, 1) + communication.HandleUpload = make(chan string, 1) // Before starting the agent, we have a control goroutine, that might // do several checks to see if the agent is still operational. @@ -50,6 +53,7 @@ func RunAgent(configuration *models.Configuration, communication *models.Communi //var decoder *ffmpeg.VideoDecoder var queue *pubsub.Queue + status := "not started" if err == nil { @@ -58,27 +62,34 @@ func RunAgent(configuration *models.Configuration, communication *models.Communi queue.SetMaxGopCount(5) // GOP time frame is set to 5. queue.WriteHeader(streams) - // Start handling the stream + // Handle the camera stream go HandleStream(infile, queue, communication) //, &wg) - // Start processing of motion + // Handle processing of motion motionCursor := queue.Oldest() var decoderMutex sync.Mutex decoder := GetVideoDecoder(streams) - go ProcessMotion(motionCursor, configuration, communication, decoder, &decoderMutex) + go computervision.ProcessMotion(motionCursor, configuration, communication, decoder, &decoderMutex) + + // Handle heartbeats + go cloud.HandleHeartBeat(configuration, communication) + + //----------- + // This will go into a blocking state, once this channel is triggered + // the agent will cleanup and restart. + status = <-communication.HandleBootstrap + + // Here we are cleaning up everything! + communication.HandleStream <- "stop" + communication.HandleHeartBeat <- "stop" + infile.Close() + queue.Close() } else { + time.Sleep(time.Second * 2) log.Log.Error("Something went wrong while opening RTSP: " + err.Error()) } - // This will go into a blocking state, once this channel is triggered - // the agent will cleanup and restart. - status := <-communication.HandleBootstrap - - // Here we are cleaning up everything! - communication.HandleStream <- "stop" - infile.Close() - queue.Close() log.Log.Debug("RunAgent: finished") return status diff --git a/machinery/src/components/ImageProcessing.go b/machinery/src/computervision/main.go similarity index 99% rename from machinery/src/components/ImageProcessing.go rename to machinery/src/computervision/main.go index 1cc6673..efd1be3 100644 --- a/machinery/src/components/ImageProcessing.go +++ b/machinery/src/computervision/main.go @@ -1,4 +1,4 @@ -package components +package computervision import ( "fmt" diff --git a/machinery/src/models/Communication.go b/machinery/src/models/Communication.go index b338523..818eea7 100644 --- a/machinery/src/models/Communication.go +++ b/machinery/src/models/Communication.go @@ -9,4 +9,6 @@ type Communication struct { HandleBootstrap chan string HandleStream chan string HandleMotion chan string + HandleUpload chan string + HandleHeartBeat chan string } diff --git a/machinery/src/components/Utils.go b/machinery/src/utils/main.go similarity index 98% rename from machinery/src/components/Utils.go rename to machinery/src/utils/main.go index 8b3257b..5769353 100644 --- a/machinery/src/components/Utils.go +++ b/machinery/src/utils/main.go @@ -1,4 +1,4 @@ -package components +package utils import ( "bytes"