Masterthesis
This commit is contained in:
parent
6de476260d
commit
a21bbcca0e
9 changed files with 140 additions and 211 deletions
|
@ -1,11 +0,0 @@
|
||||||
Iteration,Start,End
|
|
||||||
1,1602787120,1602787240
|
|
||||||
2,1602787240,1602787360
|
|
||||||
3,1602787360,1602787480
|
|
||||||
4,1602787480,1602787600
|
|
||||||
5,1602787600,1602787720
|
|
||||||
6,1602787720,1602787840
|
|
||||||
7,1602787840,1602787961
|
|
||||||
8,1602787961,1602788081
|
|
||||||
9,1602788081,1602788201
|
|
||||||
10,1602788201,1602788321
|
|
|
|
@ -23,8 +23,6 @@ var Signing bool
|
||||||
var Encryption bool
|
var Encryption bool
|
||||||
var HttpString string
|
var HttpString string
|
||||||
|
|
||||||
//var BackoffPolicy *backoff.Exponential
|
|
||||||
|
|
||||||
func SetDefaultParams() {
|
func SetDefaultParams() {
|
||||||
Packetloss = 0.0
|
Packetloss = 0.0
|
||||||
UnavailableTill = time.Now().Unix()
|
UnavailableTill = time.Now().Unix()
|
||||||
|
|
|
@ -49,13 +49,6 @@ func SetParams(w http.ResponseWriter, r *http.Request) {
|
||||||
func Reset(w http.ResponseWriter, r *http.Request) {
|
func Reset(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||||
|
|
||||||
/*
|
|
||||||
if err := device.InitServerSigningKey(); err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
config.VerifyKeys = make(map[string]map[string][]byte)
|
|
||||||
*/
|
|
||||||
|
|
||||||
database.DB.Close()
|
database.DB.Close()
|
||||||
os.Remove("sqlite.db")
|
os.Remove("sqlite.db")
|
||||||
|
|
||||||
|
|
|
@ -88,7 +88,7 @@ func PostInboxHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
if foundObject == nil {
|
if foundObject == nil {
|
||||||
_ = object.CreateObject(newActivity.Object)
|
_ = object.CreateObject(newActivity.Object)
|
||||||
/*
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
if err := json.NewEncoder(w).Encode(fmt.Sprintf("Database Error Creating Object: %s", err)); err != nil {
|
if err := json.NewEncoder(w).Encode(fmt.Sprintf("Database Error Creating Object: %s", err)); err != nil {
|
||||||
|
@ -96,10 +96,10 @@ func PostInboxHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
_ = CreateCollectionObject(utils.GenerateInboxUrl(actorName), newActivity.Object.Id)
|
_ = CreateCollectionObject(utils.GenerateInboxUrl(actorName), newActivity.Object.Id)
|
||||||
/*
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
if err := json.NewEncoder(w).Encode(fmt.Sprintf("Database Error Creating Collection Object: %s", err)); err != nil {
|
if err := json.NewEncoder(w).Encode(fmt.Sprintf("Database Error Creating Collection Object: %s", err)); err != nil {
|
||||||
|
@ -107,7 +107,7 @@ func PostInboxHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
log.Printf("%s to %s: %s", newActivity.Actor, newActivity.To, newActivity.Object.Content)
|
log.Printf("%s to %s: %s", newActivity.Actor, newActivity.To, newActivity.Object.Content)
|
||||||
} else {
|
} else {
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
|
@ -231,8 +231,6 @@ func PostOutboxHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
log.Printf("Error Sending Activity, retrying in %ss: %s", duration/1000000000, err)
|
log.Printf("Error Sending Activity, retrying in %ss: %s", duration/1000000000, err)
|
||||||
}
|
}
|
||||||
backoff.RetryNotify(operation, backoff.WithMaxRetries(backoff.NewExponentialBackOff(), 16), notify)
|
backoff.RetryNotify(operation, backoff.WithMaxRetries(backoff.NewExponentialBackOff(), 16), notify)
|
||||||
|
|
||||||
//go retryActivity(newActivity, recipient, token)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
response := OutboxResponse{
|
response := OutboxResponse{
|
||||||
|
@ -246,22 +244,6 @@ func PostOutboxHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
func retryActivity(activityToSend *activity.Activity, recipient string, token string) (err error) {
|
|
||||||
b, cancel := config.BackoffPolicy.Start(context.Background())
|
|
||||||
defer cancel()
|
|
||||||
|
|
||||||
for backoff.Continue(b) {
|
|
||||||
err := SendActivity(activityToSend, recipient, token)
|
|
||||||
if err == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
err = errors.New("Not able to send activity")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
func GetReciepientsForActivity(activityToSend *activity.Activity) (err error, recipientsWithoutDuplicates []string) {
|
func GetReciepientsForActivity(activityToSend *activity.Activity) (err error, recipientsWithoutDuplicates []string) {
|
||||||
recipients := []string{}
|
recipients := []string{}
|
||||||
if strings.Contains(activityToSend.To, config.Homeserver) {
|
if strings.Contains(activityToSend.To, config.Homeserver) {
|
||||||
|
|
24
main.go
24
main.go
|
@ -33,20 +33,8 @@ var routes = router.Routes{
|
||||||
router.Route{"GetPost", "GET", "/{actorName}/posts/{postId}", object.GetPostHandler},
|
router.Route{"GetPost", "GET", "/{actorName}/posts/{postId}", object.GetPostHandler},
|
||||||
|
|
||||||
// Collections
|
// Collections
|
||||||
/*
|
|
||||||
router.Route{"GetInbox", "GET", "/{actorName}/inbox", collection.GetInboxHandler},
|
|
||||||
router.Route{"GetOutbox", "GET", "/{actorName}/outbox", collection.GetOutboxHandler},
|
|
||||||
router.Route{"GetFollowers", "GET", "/{actorName}/followers", collection.GetFollowersHandler},
|
|
||||||
router.Route{"GetFollowing", "GET", "/{actorName}/following", collection.GetFollowingHandler},
|
|
||||||
router.Route{"GetLiked", "GET", "/{actorName}/liked", collection.GetLikedHandler},
|
|
||||||
*/
|
|
||||||
router.Route{"PostInbox", "POST", "/{actorName}/inbox/", collection.PostInboxHandler},
|
router.Route{"PostInbox", "POST", "/{actorName}/inbox/", collection.PostInboxHandler},
|
||||||
router.Route{"PostOutbox", "POST", "/{actorName}/outbox/", collection.PostOutboxHandler},
|
router.Route{"PostOutbox", "POST", "/{actorName}/outbox/", collection.PostOutboxHandler},
|
||||||
/*
|
|
||||||
router.Route{"PostFollowers", "POST", "/{actorName}/followers", collection.PostFollowersHandler},
|
|
||||||
router.Route{"PostFollowing", "POST", "/{actorName}/following", collection.PostFollowingHandler},
|
|
||||||
router.Route{"PostLiked", "POST", "/{actorName}/liked", collection.PostLikedHandler},
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -57,18 +45,6 @@ func main() {
|
||||||
}
|
}
|
||||||
log.Printf("Start homeserver on name %s", config.Homeserver)
|
log.Printf("Start homeserver on name %s", config.Homeserver)
|
||||||
|
|
||||||
/*
|
|
||||||
if err := device.InitServerSigningKey(); err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
config.VerifyKeys = make(map[string]map[string][]byte)
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
config.BackoffPolicy = backoff.NewExponential(
|
|
||||||
backoff.WithInterval(500*time.Millisecond),
|
|
||||||
backoff.WithMaxRetries(16),
|
|
||||||
)
|
|
||||||
*/
|
|
||||||
os.Remove("sqlite.db")
|
os.Remove("sqlite.db")
|
||||||
|
|
||||||
if err := database.InitDB("sqlite.db"); err != nil {
|
if err := database.InitDB("sqlite.db"); err != nil {
|
||||||
|
|
BIN
sqlite.db
BIN
sqlite.db
Binary file not shown.
|
@ -9,7 +9,6 @@ import (
|
||||||
|
|
||||||
var DB *sql.DB
|
var DB *sql.DB
|
||||||
|
|
||||||
// TODO: Change DB Structure
|
|
||||||
func InitDB(filepath string) (err error) {
|
func InitDB(filepath string) (err error) {
|
||||||
DB, err = sql.Open("sqlite3", filepath)
|
DB, err = sql.Open("sqlite3", filepath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -1,14 +1,11 @@
|
||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/ed25519"
|
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"git.nutfactory.org/hoernschen/ActivityPub/config"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func CreateToken() (err error, token string) {
|
func CreateToken() (err error, token string) {
|
||||||
|
@ -33,7 +30,6 @@ func CreateUUID() (err error, uuid string) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Check if needed
|
|
||||||
func Hash(s []byte) (err error, hashString string) {
|
func Hash(s []byte) (err error, hashString string) {
|
||||||
h := sha256.New()
|
h := sha256.New()
|
||||||
_, err = h.Write(s)
|
_, err = h.Write(s)
|
||||||
|
@ -44,33 +40,3 @@ func Hash(s []byte) (err error, hashString string) {
|
||||||
hashString = base64.StdEncoding.EncodeToString(hash)
|
hashString = base64.StdEncoding.EncodeToString(hash)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: Signing Mechanism?
|
|
||||||
func GenerateKeyPair() (publicKey ed25519.PublicKey, privateKey ed25519.PrivateKey, err error) {
|
|
||||||
publicKey, privateKey, err = ed25519.GenerateKey(nil)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func Sign(message []byte) string {
|
|
||||||
signatureBytes := ed25519.Sign(config.PrivateKey, message)
|
|
||||||
return base64.RawStdEncoding.EncodeToString(signatureBytes)
|
|
||||||
}
|
|
||||||
|
|
||||||
func SignContent(content []byte) (signatures map[string]map[string]string) {
|
|
||||||
if !config.Signing {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
signatures = make(map[string]map[string]string)
|
|
||||||
signatures[config.Homeserver] = make(map[string]string)
|
|
||||||
signatures[config.Homeserver][config.KeyId] = Sign(content)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func VerifySignature(publicKey []byte, message []byte, signature string) bool {
|
|
||||||
signatureBytes, err := base64.RawStdEncoding.DecodeString(signature)
|
|
||||||
if err != nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
ed25519.Verify(config.PublicKey, message, signatureBytes)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
|
@ -84,17 +84,43 @@ var users = []map[string][]string{
|
||||||
"user4",
|
"user4",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
map[string][]string{
|
||||||
|
"localhost": []string{
|
||||||
|
"user1",
|
||||||
|
"user2",
|
||||||
|
"user3",
|
||||||
|
"user4",
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
var servers = []string{
|
var servers = []string{
|
||||||
"143.93.38.207",
|
"143.93.38.207",
|
||||||
"143.93.38.208",
|
"143.93.38.208",
|
||||||
"143.93.38.209",
|
"143.93.38.209",
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
var servers = []string{
|
||||||
|
"localhost",
|
||||||
|
}
|
||||||
|
|
||||||
var systemParams = []SystemParams{
|
var systemParams = []SystemParams{
|
||||||
SystemParams{
|
SystemParams{
|
||||||
Id: "111110000",
|
Id: "111110101",
|
||||||
|
BytesToSend: 280,
|
||||||
|
MessagesPerSecond: 1.0,
|
||||||
|
Distribution: users[3],
|
||||||
|
Packetloss: 1,
|
||||||
|
MinutesNotAvailable: 0,
|
||||||
|
Consensus: true,
|
||||||
|
AuthentificationCheck: true,
|
||||||
|
Signing: true,
|
||||||
|
Encryption: true,
|
||||||
|
},
|
||||||
|
/*
|
||||||
|
SystemParams{
|
||||||
|
Id: "111110101",
|
||||||
BytesToSend: 280,
|
BytesToSend: 280,
|
||||||
MessagesPerSecond: 1.0,
|
MessagesPerSecond: 1.0,
|
||||||
Distribution: users[1],
|
Distribution: users[1],
|
||||||
|
@ -106,7 +132,7 @@ var systemParams = []SystemParams{
|
||||||
Encryption: true,
|
Encryption: true,
|
||||||
},
|
},
|
||||||
SystemParams{
|
SystemParams{
|
||||||
Id: "011110000",
|
Id: "011110101",
|
||||||
BytesToSend: 8,
|
BytesToSend: 8,
|
||||||
MessagesPerSecond: 1.0,
|
MessagesPerSecond: 1.0,
|
||||||
Distribution: users[1],
|
Distribution: users[1],
|
||||||
|
@ -118,7 +144,7 @@ var systemParams = []SystemParams{
|
||||||
Encryption: true,
|
Encryption: true,
|
||||||
},
|
},
|
||||||
SystemParams{
|
SystemParams{
|
||||||
Id: "211110000",
|
Id: "211110101",
|
||||||
BytesToSend: 512,
|
BytesToSend: 512,
|
||||||
MessagesPerSecond: 1.0,
|
MessagesPerSecond: 1.0,
|
||||||
Distribution: users[1],
|
Distribution: users[1],
|
||||||
|
@ -130,7 +156,7 @@ var systemParams = []SystemParams{
|
||||||
Encryption: true,
|
Encryption: true,
|
||||||
},
|
},
|
||||||
SystemParams{
|
SystemParams{
|
||||||
Id: "101110000",
|
Id: "101110101",
|
||||||
BytesToSend: 280,
|
BytesToSend: 280,
|
||||||
MessagesPerSecond: 0.1,
|
MessagesPerSecond: 0.1,
|
||||||
Distribution: users[1],
|
Distribution: users[1],
|
||||||
|
@ -142,7 +168,7 @@ var systemParams = []SystemParams{
|
||||||
Encryption: true,
|
Encryption: true,
|
||||||
},
|
},
|
||||||
SystemParams{
|
SystemParams{
|
||||||
Id: "121110000",
|
Id: "121110101",
|
||||||
BytesToSend: 280,
|
BytesToSend: 280,
|
||||||
MessagesPerSecond: 10.0,
|
MessagesPerSecond: 10.0,
|
||||||
Distribution: users[1],
|
Distribution: users[1],
|
||||||
|
@ -154,7 +180,7 @@ var systemParams = []SystemParams{
|
||||||
Encryption: true,
|
Encryption: true,
|
||||||
},
|
},
|
||||||
SystemParams{
|
SystemParams{
|
||||||
Id: "110110000",
|
Id: "110110101",
|
||||||
BytesToSend: 280,
|
BytesToSend: 280,
|
||||||
MessagesPerSecond: 1.0,
|
MessagesPerSecond: 1.0,
|
||||||
Distribution: users[0],
|
Distribution: users[0],
|
||||||
|
@ -166,7 +192,7 @@ var systemParams = []SystemParams{
|
||||||
Encryption: true,
|
Encryption: true,
|
||||||
},
|
},
|
||||||
SystemParams{
|
SystemParams{
|
||||||
Id: "112110000",
|
Id: "112110101",
|
||||||
BytesToSend: 280,
|
BytesToSend: 280,
|
||||||
MessagesPerSecond: 1.0,
|
MessagesPerSecond: 1.0,
|
||||||
Distribution: users[2],
|
Distribution: users[2],
|
||||||
|
@ -178,7 +204,7 @@ var systemParams = []SystemParams{
|
||||||
Encryption: true,
|
Encryption: true,
|
||||||
},
|
},
|
||||||
SystemParams{
|
SystemParams{
|
||||||
Id: "111010000",
|
Id: "111010101",
|
||||||
BytesToSend: 280,
|
BytesToSend: 280,
|
||||||
MessagesPerSecond: 1.0,
|
MessagesPerSecond: 1.0,
|
||||||
Distribution: users[1],
|
Distribution: users[1],
|
||||||
|
@ -190,7 +216,7 @@ var systemParams = []SystemParams{
|
||||||
Encryption: true,
|
Encryption: true,
|
||||||
},
|
},
|
||||||
SystemParams{
|
SystemParams{
|
||||||
Id: "111210000",
|
Id: "111210101",
|
||||||
BytesToSend: 280,
|
BytesToSend: 280,
|
||||||
MessagesPerSecond: 1.0,
|
MessagesPerSecond: 1.0,
|
||||||
Distribution: users[1],
|
Distribution: users[1],
|
||||||
|
|
Loading…
Reference in a new issue