Masterthesis

This commit is contained in:
hoernschen 2020-11-27 05:46:17 +01:00
parent 6de476260d
commit a21bbcca0e
9 changed files with 140 additions and 211 deletions

View file

@ -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
1 Iteration Start End
2 1 1602787120 1602787240
3 2 1602787240 1602787360
4 3 1602787360 1602787480
5 4 1602787480 1602787600
6 5 1602787600 1602787720
7 6 1602787720 1602787840
8 7 1602787840 1602787961
9 8 1602787961 1602788081
10 9 1602788081 1602788201
11 10 1602788201 1602788321

View file

@ -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()

View file

@ -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")

View file

@ -88,7 +88,7 @@ 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 {
@ -96,10 +96,10 @@ func PostInboxHandler(w http.ResponseWriter, r *http.Request) {
}
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 {
@ -107,7 +107,7 @@ func PostInboxHandler(w http.ResponseWriter, r *http.Request) {
}
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) {

24
main.go
View file

@ -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 {

BIN
sqlite.db

Binary file not shown.

View file

@ -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 {

View file

@ -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
}

View file

@ -84,17 +84,43 @@ 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[3],
Packetloss: 1,
MinutesNotAvailable: 0,
Consensus: true,
AuthentificationCheck: true,
Signing: true,
Encryption: true,
},
/*
SystemParams{
Id: "111110101",
BytesToSend: 280,
MessagesPerSecond: 1.0,
Distribution: users[1],
@ -106,7 +132,7 @@ var systemParams = []SystemParams{
Encryption: true,
},
SystemParams{
Id: "011110000",
Id: "011110101",
BytesToSend: 8,
MessagesPerSecond: 1.0,
Distribution: users[1],
@ -118,7 +144,7 @@ var systemParams = []SystemParams{
Encryption: true,
},
SystemParams{
Id: "211110000",
Id: "211110101",
BytesToSend: 512,
MessagesPerSecond: 1.0,
Distribution: users[1],
@ -130,7 +156,7 @@ var systemParams = []SystemParams{
Encryption: true,
},
SystemParams{
Id: "101110000",
Id: "101110101",
BytesToSend: 280,
MessagesPerSecond: 0.1,
Distribution: users[1],
@ -142,7 +168,7 @@ var systemParams = []SystemParams{
Encryption: true,
},
SystemParams{
Id: "121110000",
Id: "121110101",
BytesToSend: 280,
MessagesPerSecond: 10.0,
Distribution: users[1],
@ -154,7 +180,7 @@ var systemParams = []SystemParams{
Encryption: true,
},
SystemParams{
Id: "110110000",
Id: "110110101",
BytesToSend: 280,
MessagesPerSecond: 1.0,
Distribution: users[0],
@ -166,7 +192,7 @@ var systemParams = []SystemParams{
Encryption: true,
},
SystemParams{
Id: "112110000",
Id: "112110101",
BytesToSend: 280,
MessagesPerSecond: 1.0,
Distribution: users[2],
@ -178,7 +204,7 @@ var systemParams = []SystemParams{
Encryption: true,
},
SystemParams{
Id: "111010000",
Id: "111010101",
BytesToSend: 280,
MessagesPerSecond: 1.0,
Distribution: users[1],
@ -190,7 +216,7 @@ var systemParams = []SystemParams{
Encryption: true,
},
SystemParams{
Id: "111210000",
Id: "111210101",
BytesToSend: 280,
MessagesPerSecond: 1.0,
Distribution: users[1],