diff --git a/1602787120 Baseline Measurement.csv b/1602787120 Baseline Measurement.csv deleted file mode 100644 index 3e61a7b..0000000 --- a/1602787120 Baseline Measurement.csv +++ /dev/null @@ -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 diff --git a/config/config.go b/config/config.go index 313e8aa..efb23c2 100644 --- a/config/config.go +++ b/config/config.go @@ -23,8 +23,6 @@ var Signing bool var Encryption bool var HttpString string -//var BackoffPolicy *backoff.Exponential - func SetDefaultParams() { Packetloss = 0.0 UnavailableTill = time.Now().Unix() diff --git a/config/configController.go b/config/configController.go index 74029ce..c898b11 100644 --- a/config/configController.go +++ b/config/configController.go @@ -49,13 +49,6 @@ func SetParams(w http.ResponseWriter, r *http.Request) { func Reset(w http.ResponseWriter, r *http.Request) { 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() os.Remove("sqlite.db") diff --git a/entities/collection/collectionController.go b/entities/collection/collectionController.go index 1d4c8ce..744364f 100644 --- a/entities/collection/collectionController.go +++ b/entities/collection/collectionController.go @@ -88,26 +88,26 @@ func PostInboxHandler(w http.ResponseWriter, r *http.Request) { } if foundObject == nil { _ = object.CreateObject(newActivity.Object) - /* - if err != nil { - w.WriteHeader(http.StatusBadRequest) - if err := json.NewEncoder(w).Encode(fmt.Sprintf("Database Error Creating Object: %s", err)); err != nil { - panic(err) - } - return - } - */ - } - _ = CreateCollectionObject(utils.GenerateInboxUrl(actorName), newActivity.Object.Id) - /* + if err != nil { 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 Object: %s", err)); err != nil { panic(err) } return } - */ + + } + _ = CreateCollectionObject(utils.GenerateInboxUrl(actorName), newActivity.Object.Id) + + if err != nil { + w.WriteHeader(http.StatusBadRequest) + if err := json.NewEncoder(w).Encode(fmt.Sprintf("Database Error Creating Collection Object: %s", err)); err != nil { + panic(err) + } + return + } + log.Printf("%s to %s: %s", newActivity.Actor, newActivity.To, newActivity.Object.Content) } else { 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) } backoff.RetryNotify(operation, backoff.WithMaxRetries(backoff.NewExponentialBackOff(), 16), notify) - - //go retryActivity(newActivity, recipient, token) } 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) { recipients := []string{} if strings.Contains(activityToSend.To, config.Homeserver) { diff --git a/main.go b/main.go index 53eeac9..ef631ea 100644 --- a/main.go +++ b/main.go @@ -33,20 +33,8 @@ var routes = router.Routes{ router.Route{"GetPost", "GET", "/{actorName}/posts/{postId}", object.GetPostHandler}, // 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{"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() { @@ -57,18 +45,6 @@ func main() { } 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") if err := database.InitDB("sqlite.db"); err != nil { diff --git a/sqlite.db b/sqlite.db index f7bc898..90f72da 100644 Binary files a/sqlite.db and b/sqlite.db differ diff --git a/utils/database/databaseConnector.go b/utils/database/databaseConnector.go index 7901b81..489ea41 100644 --- a/utils/database/databaseConnector.go +++ b/utils/database/databaseConnector.go @@ -9,7 +9,6 @@ import ( var DB *sql.DB -// TODO: Change DB Structure func InitDB(filepath string) (err error) { DB, err = sql.Open("sqlite3", filepath) if err != nil { diff --git a/utils/encryptionService.go b/utils/encryptionService.go index 4960cb4..69c65fa 100644 --- a/utils/encryptionService.go +++ b/utils/encryptionService.go @@ -1,14 +1,11 @@ package utils import ( - "crypto/ed25519" "crypto/rand" "crypto/sha256" "encoding/base64" "fmt" "log" - - "git.nutfactory.org/hoernschen/ActivityPub/config" ) func CreateToken() (err error, token string) { @@ -33,7 +30,6 @@ func CreateUUID() (err error, uuid string) { return } -// TODO: Check if needed func Hash(s []byte) (err error, hashString string) { h := sha256.New() _, err = h.Write(s) @@ -44,33 +40,3 @@ func Hash(s []byte) (err error, hashString string) { hashString = base64.StdEncoding.EncodeToString(hash) 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 -} diff --git a/workloadGenerator.go b/workloadGenerator.go index 21d20c1..38b6640 100644 --- a/workloadGenerator.go +++ b/workloadGenerator.go @@ -84,20 +84,33 @@ var users = []map[string][]string{ "user4", }, }, + map[string][]string{ + "localhost": []string{ + "user1", + "user2", + "user3", + "user4", + }, + }, } +/* var servers = []string{ "143.93.38.207", "143.93.38.208", "143.93.38.209", } +*/ +var servers = []string{ + "localhost", +} var systemParams = []SystemParams{ SystemParams{ - Id: "111110000", + Id: "111110101", BytesToSend: 280, MessagesPerSecond: 1.0, - Distribution: users[1], + Distribution: users[3], Packetloss: 1, MinutesNotAvailable: 0, Consensus: true, @@ -105,115 +118,128 @@ var systemParams = []SystemParams{ Signing: true, Encryption: true, }, - SystemParams{ - Id: "011110000", - BytesToSend: 8, - MessagesPerSecond: 1.0, - Distribution: users[1], - Packetloss: 1, - MinutesNotAvailable: 0, - Consensus: true, - AuthentificationCheck: true, - Signing: true, - Encryption: true, - }, - SystemParams{ - Id: "211110000", - BytesToSend: 512, - MessagesPerSecond: 1.0, - Distribution: users[1], - Packetloss: 1, - MinutesNotAvailable: 0, - Consensus: true, - AuthentificationCheck: true, - Signing: true, - Encryption: true, - }, - SystemParams{ - Id: "101110000", - BytesToSend: 280, - MessagesPerSecond: 0.1, - Distribution: users[1], - Packetloss: 1, - MinutesNotAvailable: 0, - Consensus: true, - AuthentificationCheck: true, - Signing: true, - Encryption: true, - }, - SystemParams{ - Id: "121110000", - BytesToSend: 280, - MessagesPerSecond: 10.0, - Distribution: users[1], - Packetloss: 1, - MinutesNotAvailable: 0, - Consensus: true, - AuthentificationCheck: true, - Signing: true, - Encryption: true, - }, - SystemParams{ - Id: "110110000", - BytesToSend: 280, - MessagesPerSecond: 1.0, - Distribution: users[0], - Packetloss: 1, - MinutesNotAvailable: 0, - Consensus: true, - AuthentificationCheck: true, - Signing: true, - Encryption: true, - }, - SystemParams{ - Id: "112110000", - BytesToSend: 280, - MessagesPerSecond: 1.0, - Distribution: users[2], - Packetloss: 1, - MinutesNotAvailable: 0, - Consensus: true, - AuthentificationCheck: true, - Signing: true, - Encryption: true, - }, - SystemParams{ - Id: "111010000", - BytesToSend: 280, - MessagesPerSecond: 1.0, - Distribution: users[1], - Packetloss: 0, - MinutesNotAvailable: 0, - Consensus: true, - AuthentificationCheck: true, - Signing: true, - Encryption: true, - }, - SystemParams{ - Id: "111210000", - BytesToSend: 280, - MessagesPerSecond: 1.0, - Distribution: users[1], - Packetloss: 20, - MinutesNotAvailable: 0, - Consensus: true, - AuthentificationCheck: true, - Signing: true, - Encryption: true, - }, /* SystemParams{ - Id: "111120000", + Id: "111110101", BytesToSend: 280, MessagesPerSecond: 1.0, Distribution: users[1], Packetloss: 1, - MinutesNotAvailable: 1, + MinutesNotAvailable: 0, Consensus: true, AuthentificationCheck: true, Signing: true, Encryption: true, }, + SystemParams{ + Id: "011110101", + BytesToSend: 8, + MessagesPerSecond: 1.0, + Distribution: users[1], + Packetloss: 1, + MinutesNotAvailable: 0, + Consensus: true, + AuthentificationCheck: true, + Signing: true, + Encryption: true, + }, + SystemParams{ + Id: "211110101", + BytesToSend: 512, + MessagesPerSecond: 1.0, + Distribution: users[1], + Packetloss: 1, + MinutesNotAvailable: 0, + Consensus: true, + AuthentificationCheck: true, + Signing: true, + Encryption: true, + }, + SystemParams{ + Id: "101110101", + BytesToSend: 280, + MessagesPerSecond: 0.1, + Distribution: users[1], + Packetloss: 1, + MinutesNotAvailable: 0, + Consensus: true, + AuthentificationCheck: true, + Signing: true, + Encryption: true, + }, + SystemParams{ + Id: "121110101", + BytesToSend: 280, + MessagesPerSecond: 10.0, + Distribution: users[1], + Packetloss: 1, + MinutesNotAvailable: 0, + Consensus: true, + AuthentificationCheck: true, + Signing: true, + Encryption: true, + }, + SystemParams{ + Id: "110110101", + BytesToSend: 280, + MessagesPerSecond: 1.0, + Distribution: users[0], + Packetloss: 1, + MinutesNotAvailable: 0, + Consensus: true, + AuthentificationCheck: true, + Signing: true, + Encryption: true, + }, + SystemParams{ + Id: "112110101", + BytesToSend: 280, + MessagesPerSecond: 1.0, + Distribution: users[2], + Packetloss: 1, + MinutesNotAvailable: 0, + Consensus: true, + AuthentificationCheck: true, + Signing: true, + Encryption: true, + }, + SystemParams{ + Id: "111010101", + BytesToSend: 280, + MessagesPerSecond: 1.0, + Distribution: users[1], + Packetloss: 0, + MinutesNotAvailable: 0, + Consensus: true, + AuthentificationCheck: true, + Signing: true, + Encryption: true, + }, + SystemParams{ + Id: "111210101", + BytesToSend: 280, + MessagesPerSecond: 1.0, + Distribution: users[1], + Packetloss: 20, + MinutesNotAvailable: 0, + Consensus: true, + AuthentificationCheck: true, + Signing: true, + Encryption: true, + }, + /* + SystemParams{ + Id: "111120000", + BytesToSend: 280, + MessagesPerSecond: 1.0, + Distribution: users[1], + Packetloss: 1, + MinutesNotAvailable: 1, + Consensus: true, + AuthentificationCheck: true, + Signing: true, + Encryption: true, + }, */ }