distributor: storage and file handling

fix #11 #2
This commit is contained in:
Geno 2021-09-14 21:37:37 +02:00
parent f24a76a62e
commit 8fda0be59c
6 changed files with 118 additions and 65 deletions

View File

@ -59,6 +59,6 @@ The message sender `from` should be validated from distributor, for not recievin
## Wordings
We are using over the complete system three kind of **tokens**:
- **Public Token** which is part of the *Endpoint* and is for using between Gateway and Application-Server
- **External Token** which is used between Gateway and Distributor
- **Internal Token** which is used between Distributor and Application
- **Endpoint Token** which is part of the *Endpoint* and is for using between Gateway and Application-Server
- **Public Token** which is used between Gateway and Distributor
- **App Token** which is used between Distributor and Application

View File

@ -1,3 +1,7 @@
# if not given placed in XDG_CONFIG_HOME/unifiedpushxmpp/database.db
storage_path = ""
[xmpp]
login = "YOUR-ACCOUNT@chat.sum7.eu"
password = "CHANGEME"
gateway = "up.chat.sum7.eu"

View File

@ -3,26 +3,34 @@ module dev.sum7.eu/genofire/unified-push-xmpp/distributor
go 1.17
require (
dev.sum7.eu/genofire/golang-lib v0.0.0-20210907112925-492a959d8452
dev.sum7.eu/genofire/golang-lib v0.0.0-20210912204316-9b2fe62df536
dev.sum7.eu/genofire/unified-push-xmpp/messages v0.0.0-20210914093612-4a88e1d4a772
github.com/bdlm/log v0.1.20
github.com/google/uuid v1.3.0
mellium.im/sasl v0.2.1
mellium.im/xmlstream v0.15.3-0.20210221202126-7cc1407dad4c
mellium.im/xmpp v0.19.0
unifiedpush.org/go/np2p_dbus v0.0.0-20210906135733-42e59cd82376
unifiedpush.org/go/np2p_dbus v0.0.0-20210914192133-e2c19b86a23f
)
require (
dev.sum7.eu/genofire/unified-push-xmpp/messages v0.0.0-00010101000000-000000000000 // indirect
github.com/bdlm/std v1.0.1 // indirect
github.com/godbus/dbus/v5 v5.0.4 // indirect
github.com/godbus/dbus/v5 v5.0.5 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.2 // indirect
github.com/mattn/go-sqlite3 v1.14.8 // indirect
github.com/naoina/go-stringutil v0.1.0 // indirect
github.com/naoina/toml v0.1.1 // indirect
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 // indirect
golang.org/x/sys v0.0.0-20210903071746-97244b99971b // indirect
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 // indirect
golang.org/x/text v0.3.3 // indirect
golang.org/x/tools v0.0.0-20200103221440-774c71fcf114 // indirect
golang.org/x/mod v0.5.0 // indirect
golang.org/x/net v0.0.0-20210913180222-943fd674d43e // indirect
golang.org/x/sys v0.0.0-20210910150752-751e447fb3d0 // indirect
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/tools v0.1.5 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
gorm.io/driver/sqlite v1.1.5 // indirect
gorm.io/gorm v1.21.15 // indirect
mellium.im/reader v0.1.0 // indirect
)

View File

@ -2,6 +2,8 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
dev.sum7.eu/genofire/golang-lib v0.0.0-20210907112925-492a959d8452 h1:wk6ty27VJzb4OEW21wsakgKjr+AB9dqNnJm5EDkRELg=
dev.sum7.eu/genofire/golang-lib v0.0.0-20210907112925-492a959d8452/go.mod h1:8fBNwMOpKq6bWHISrivkcs65mUBHiO44THbqhjeOoas=
dev.sum7.eu/genofire/golang-lib v0.0.0-20210912204316-9b2fe62df536 h1:Q6l6hQTYqFT9bNpI0a1JL3rcmEQIyK2uUnuCaH1EXuo=
dev.sum7.eu/genofire/golang-lib v0.0.0-20210912204316-9b2fe62df536/go.mod h1:8fBNwMOpKq6bWHISrivkcs65mUBHiO44THbqhjeOoas=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs=
@ -108,6 +110,8 @@ github.com/godbus/dbus v4.1.0+incompatible h1:WqqLRTsQic3apZUK9qC5sGNfXthmPXzUZ7
github.com/godbus/dbus v4.1.0+incompatible/go.mod h1:/YcGZj5zSblfDWMMoOzV4fas9FZnQYTkDnsGvmh2Grw=
github.com/godbus/dbus/v5 v5.0.4 h1:9349emZab16e7zQvpmsbtjc18ykshndd8y2PG3sgJbA=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/godbus/dbus/v5 v5.0.5 h1:9Eg0XUhQxtkV8ykTMKtMMYY72g4NgxtRq4jgh4Ih5YM=
github.com/godbus/dbus/v5 v5.0.5/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/gofrs/uuid v3.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/gogo/googleapis v1.1.0/go.mod h1:gf4bu3Q80BeJ6H1S1vYPm8/ELATdvryBaNFGgqEef3s=
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
@ -144,6 +148,8 @@ github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm4
github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.2.0/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/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg=
github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
@ -228,8 +234,10 @@ github.com/jackc/puddle v0.0.0-20190608224051-11cab39313c9/go.mod h1:m4B5Dj62Y0f
github.com/jackc/puddle v1.1.0/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
github.com/jackc/puddle v1.1.1/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
github.com/jackc/puddle v1.1.3/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jinzhu/now v1.1.1/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/jinzhu/now v1.1.2 h1:eVKgfIdy9b6zbWBMgFpfDPoAMifwSZagU9HmEU6zgiI=
github.com/jinzhu/now v1.1.2/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
@ -282,6 +290,7 @@ github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Ky
github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/mattn/go-sqlite3 v1.14.0/go.mod h1:JIl7NbARA7phWnGvh0LKTyg7S9BA+6gx71ShQilpsus=
github.com/mattn/go-sqlite3 v1.14.5/go.mod h1:WVKg1VTActs4Qso6iwGbiFih2UIHo0ENGwNd0Lj+XmI=
github.com/mattn/go-sqlite3 v1.14.8 h1:gDp86IdQsN/xWjIEmr9MF6o9mpksUgh0fu+9ByFxzIU=
github.com/mattn/go-sqlite3 v1.14.8/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/memcachier/mc v2.0.1+incompatible/go.mod h1:7bkvFE61leUBvXz+yxsOnGBQSZpBSPIMUQSmmSHvuXc=
@ -454,6 +463,8 @@ golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHl
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
golang.org/x/mod v0.5.0 h1:UG21uOlmZabA4fW5i7ZX6bjw1xELEGg/ZLgZq9auk/Q=
golang.org/x/mod v0.5.0/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro=
golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
@ -477,6 +488,8 @@ golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81R
golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 h1:qWPm9rbaAMKs8Bq/9LRpbMqxWRVUAQwMI9fVrssnTfw=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210913180222-943fd674d43e h1:+b/22bPvDYt4NPDcy4xAGCmON713ONAWFeY3Z7I3tR8=
golang.org/x/net v0.0.0-20210913180222-943fd674d43e/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@ -518,13 +531,19 @@ golang.org/x/sys v0.0.0-20210309074719-68d13333faf2/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210903071746-97244b99971b h1:3Dq0eVHn0uaQJmPO+/aYPI/fRMqdrVDbu7MQcku54gg=
golang.org/x/sys v0.0.0-20210903071746-97244b99971b/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210910150752-751e447fb3d0 h1:xrCZDmdtoloIiooiA9q0OQb9r8HejIHYoHGhGCe1pGg=
golang.org/x/sys v0.0.0-20210910150752-751e447fb3d0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b h1:9zKuko04nR4gjZ4+DNjHqRlAJqbJETHwiNKDqTfOjfE=
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
@ -544,11 +563,14 @@ golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtn
golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200103221440-774c71fcf114 h1:DnSr2mCsxyCE6ZgIkmcWUQY2R5cH/6wL7eIxEmQOMSE=
golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/tools v0.1.5 h1:ouewzE6p+/VEB31YYnTbEJdi8pFqKp4P4n85vwo3DHA=
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/xerrors v0.0.0-20190410155217-1f06c39b4373/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/api v0.3.1/go.mod h1:6wY9I6uQWHQ8EM57III9mq/AjF+i8G65rmVagqKMtkk=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
@ -608,6 +630,8 @@ gorm.io/driver/postgres v1.0.8/go.mod h1:4eOzrI1MUfm6ObJU/UcmbXyiHSs8jSwH95G5P5d
gorm.io/driver/postgres v1.1.0/go.mod h1:hXQIwafeRjJvUm+OMxcFWyswJ/vevcpPLlGocwAwuqw=
gorm.io/driver/sqlite v1.1.1/go.mod h1:hm2olEcl8Tmsc6eZyxYSeznnsDaMqamBvEXLNtBg4cI=
gorm.io/driver/sqlite v1.1.4/go.mod h1:mJCeTFr7+crvS+TRnWc5Z3UvwxUN1BGBLMrf5LA9DYw=
gorm.io/driver/sqlite v1.1.5 h1:JU8G59VyKu1x1RMQgjefQnkZjDe9wHc1kARDZPu5dZs=
gorm.io/driver/sqlite v1.1.5/go.mod h1:NpaYMcVKEh6vLJ47VP6T7Weieu4H1Drs3dGD/K6GrGc=
gorm.io/driver/sqlserver v1.0.2/go.mod h1:gb0Y9QePGgqjzrVyTQUZeh9zkd5v0iz71cM1B4ZycEY=
gorm.io/driver/sqlserver v1.0.7/go.mod h1:ng66aHI47ZIKz/vvnxzDoonzmTS8HXP+JYlgg67wOog=
gorm.io/gorm v1.9.19/go.mod h1:0HFTzE/SqkGTzK6TlDPPQbAYCluiVvhzoA1+aVyzenw=
@ -619,6 +643,8 @@ gorm.io/gorm v1.21.9/go.mod h1:F+OptMscr0P2F2qU97WT1WimdH9GaQPoDW7AYd5i2Y0=
gorm.io/gorm v1.21.11/go.mod h1:F+OptMscr0P2F2qU97WT1WimdH9GaQPoDW7AYd5i2Y0=
gorm.io/gorm v1.21.12/go.mod h1:F+OptMscr0P2F2qU97WT1WimdH9GaQPoDW7AYd5i2Y0=
gorm.io/gorm v1.21.14/go.mod h1:F+OptMscr0P2F2qU97WT1WimdH9GaQPoDW7AYd5i2Y0=
gorm.io/gorm v1.21.15 h1:gAyaDoPw0lCyrSFWhBlahbUA1U4P5RViC1uIqoB+1Rk=
gorm.io/gorm v1.21.15/go.mod h1:F+OptMscr0P2F2qU97WT1WimdH9GaQPoDW7AYd5i2Y0=
gorm.io/plugin/prometheus v0.0.0-20210507023802-dc84a49b85d1/go.mod h1:NUWDZYJguGM83quFGTS8kj1a1bCTgxkx4+CJkF6xKhs=
honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
@ -637,3 +663,7 @@ sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
sourcegraph.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0/go.mod h1:hI742Nqp5OhwiqlzhgfbWU4mW4yO10fP+LoT9WOswdU=
unifiedpush.org/go/np2p_dbus v0.0.0-20210906135733-42e59cd82376 h1:fmedHMlfVgVnIbVHux48A5dtylXRIHfD9xiScfx7Z4Y=
unifiedpush.org/go/np2p_dbus v0.0.0-20210906135733-42e59cd82376/go.mod h1:sNyBXQNpWeAlLUUGwWJWWIsOjXfl8DIWhSHst8pQVPM=
unifiedpush.org/go/np2p_dbus v0.0.0-20210914145056-32561e01e27f h1:KxziUej4ZthAyhLv5+1QfGAfauZUKjHBXLq4pq+cuZI=
unifiedpush.org/go/np2p_dbus v0.0.0-20210914145056-32561e01e27f/go.mod h1:Sr2YTFOqwtdoF0a4pnkducazclG7c/pmsoq1xKsDrNw=
unifiedpush.org/go/np2p_dbus v0.0.0-20210914192133-e2c19b86a23f h1:FGMA1/urm5gaut8SYeFmWsky1imO6D6R4fuE45mySMU=
unifiedpush.org/go/np2p_dbus v0.0.0-20210914192133-e2c19b86a23f/go.mod h1:Sr2YTFOqwtdoF0a4pnkducazclG7c/pmsoq1xKsDrNw=

View File

@ -1,53 +1,60 @@
package main
import (
"errors"
"flag"
"os"
"path/filepath"
"dev.sum7.eu/genofire/golang-lib/file"
"github.com/bdlm/log"
"unifiedpush.org/go/np2p_dbus/distributor"
"unifiedpush.org/go/np2p_dbus/storage"
)
var dbus *distributor.DBus
type configData struct {
StoragePath string `toml"storage_path"`
XMPP XMPPService `toml:"xmpp"`
}
func defaultPath(given, filename string) string {
if given != "" {
return given
}
basedir := os.Getenv("XDG_CONFIG_HOME")
if len(basedir) == 0 {
basedir = os.Getenv("HOME")
if len(basedir) == 0 {
basedir = "./" // FIXME: set to cwd if dunno wth is going on
}
basedir = filepath.Join(basedir, ".config")
}
basedir = filepath.Join(basedir, "unifiedpushxmpp")
os.MkdirAll(basedir, 0o700)
return filepath.Join(basedir, filename)
}
func main() {
configPath := "config.toml"
configPath := ""
flag.StringVar(&configPath, "c", configPath, "path to configuration file")
flag.Parse()
config := &XMPPService{}
if err := file.ReadTOML(configPath, config); err != nil {
config := &configData{}
if err := file.ReadTOML(defaultPath(configPath, "config.toml"), config); err != nil {
log.Panicf("open config file: %s", err)
}
store, err := storage.InitStorage(defaultPath(config.StoragePath, "database.db"))
if err != nil {
log.Panicf("open storage: %s", err)
}
dbus = distributor.NewDBus("org.unifiedpush.Distributor.xmpp")
dbus.StartHandling(config)
dbus.StartHandling(&config.XMPP)
log.Info("startup")
if err := config.Run(dbus); err != nil {
if err := config.XMPP.Run(dbus, store); err != nil {
log.Errorf("startup xmpp: %v", err)
}
}
type handler struct {
}
func (h handler) Register(appName, token string) (string, string, error) {
log.WithFields(map[string]interface{}{
"name": appName,
"token": token,
}).Info("distributor-register")
endpoint := "https://up.chat.sum7.eu/UP?appid=" + appName + "&token=" + token
if endpoint != "" {
return endpoint, "", nil
}
return "", "reason to app", errors.New("Unknown error")
}
func (h handler) Unregister(token string) {
log.WithFields(map[string]interface{}{
"token": token,
}).Info("distributor-unregister")
appID := ""
_ = dbus.NewConnector(appID).Unregistered(token)
}

View File

@ -5,11 +5,10 @@ import (
"crypto/tls"
"encoding/xml"
"errors"
"fmt"
"io"
"strings"
"github.com/bdlm/log"
"github.com/google/uuid"
"mellium.im/sasl"
"mellium.im/xmlstream"
"mellium.im/xmpp"
@ -17,6 +16,7 @@ import (
"mellium.im/xmpp/mux"
"mellium.im/xmpp/stanza"
"unifiedpush.org/go/np2p_dbus/distributor"
"unifiedpush.org/go/np2p_dbus/storage"
"dev.sum7.eu/genofire/unified-push-xmpp/messages"
)
@ -27,11 +27,13 @@ type XMPPService struct {
Gateway string
dbus *distributor.DBus
session *xmpp.Session
store *storage.Storage
}
func (s *XMPPService) Run(dbus *distributor.DBus) error {
func (s *XMPPService) Run(dbus *distributor.DBus, store *storage.Storage) error {
var err error
s.dbus = dbus
s.store = store
j := jid.MustParse(s.Login)
if s.session, err = xmpp.DialClientSession(
context.TODO(), j,
@ -91,25 +93,21 @@ func (s *XMPPService) message(msgHead stanza.Message, t xmlstream.TokenReadEncod
return nil
}
logger = logger.WithFields(map[string]interface{}{
"externalToken": msg.Token,
"content": msg.Body,
"publicToken": msg.Token,
"content": msg.Body,
})
//TODO Lockup for appid by token in storage
token := strings.SplitN(msg.Token, "/", 2)
if len(token) != 2 {
log.WithField("token", msg.Token).Errorf("unable to parse token")
return nil
conn := s.store.GetConnectionbyPublic(msg.Token)
if conn == nil {
logger.Warnf("no appID and appToken found for publicToken")
}
appID := token[0]
internalToken := token[1]
logger = logger.WithFields(map[string]interface{}{
"appID": appID,
"internalToken": internalToken,
"appID": conn.AppID,
"appToken": conn.AppToken,
})
if s.dbus.
NewConnector(appID).
Message(internalToken, msg.Body, msgHead.ID) != nil {
NewConnector(conn.AppID).
Message(conn.AppToken, msg.Body, msgHead.ID) != nil {
logger.Errorf("Error send unified push: %q", err)
return nil
}
@ -119,10 +117,12 @@ func (s *XMPPService) message(msgHead stanza.Message, t xmlstream.TokenReadEncod
}
// Register handler of DBUS Distribution
func (s *XMPPService) Register(appName, token string) (string, string, error) {
func (s *XMPPService) Register(appID, appToken string) (string, string, error) {
publicToken := uuid.New().String()
logger := log.WithFields(map[string]interface{}{
"name": appName,
"token": token,
"appID": appID,
"appToken": appToken,
"publicToken": publicToken,
})
iq := messages.RegisterIQ{
IQ: stanza.IQ{
@ -130,8 +130,7 @@ func (s *XMPPService) Register(appName, token string) (string, string, error) {
To: jid.MustParse(s.Gateway),
},
}
externalToken := fmt.Sprintf("%s/%s", appName, token)
iq.Register.Token = &messages.TokenData{Body: externalToken}
iq.Register.Token = &messages.TokenData{Body: publicToken}
t, err := s.session.EncodeIQ(context.TODO(), iq)
if err != nil {
logger.Errorf("xmpp send IQ for register: %v", err)
@ -150,7 +149,9 @@ func (s *XMPPService) Register(appName, token string) (string, string, error) {
}
if endpoint := iqRegister.Register.Endpoint; endpoint != nil {
logger.WithField("endpoint", endpoint.Body).Info("success")
return endpoint.Body, "", nil
// update Endpoint
conn := s.store.NewConnectionWithToken(appID, appToken, publicToken, endpoint.Body)
return conn.Endpoint, "", nil
}
errStr := "Unknown Error"
if errr := iqRegister.Register.Error; errr != nil {
@ -163,9 +164,12 @@ func (s *XMPPService) Register(appName, token string) (string, string, error) {
// Unregister handler of DBUS Distribution
func (xs *XMPPService) Unregister(token string) {
conn, _ := xs.store.DeleteConnection(token)
log.WithFields(map[string]interface{}{
"token": token,
"appID": conn.AppID,
"appToken": conn.AppToken,
"publicToken": conn.PublicToken,
"endpoint": conn.Endpoint,
}).Info("distributor-unregister")
appID := ""
_ = xs.dbus.NewConnector(appID).Unregistered(token)
_ = xs.dbus.NewConnector(conn.AppID).Unregistered(conn.AppToken)
}