|
@@ -73,7 +73,7 @@ func NewEntries(inputTweets []Tweet, whereTo int) {
|
|
|
//todo! add round to pirquery only get tweets that have been posted from that round onward
|
|
|
func GetTweets(pirQuery []byte, dataLength int, whereFrom int, pubKey [32]byte) []byte {
|
|
|
//fmt.Println("query", pirQuery)
|
|
|
- //fmt.Println("dbR", dbR)
|
|
|
+ fmt.Println("dbR", dbR)
|
|
|
tmpdb := dbR
|
|
|
if whereFrom == 1 {
|
|
|
tmpdb = archive
|
|
@@ -98,7 +98,7 @@ func GetTweets(pirQuery []byte, dataLength int, whereFrom int, pubKey [32]byte)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- return tweetsToByteArray(tweetsToReturn)
|
|
|
+ return tweetsToByteArray(tweetsToReturn, whereFrom)
|
|
|
}
|
|
|
|
|
|
func maxTweetAmount(whereFrom int) int {
|
|
@@ -131,42 +131,109 @@ func getNamesForTopics(wantedIndices []byte, whereFrom int) []string {
|
|
|
}
|
|
|
|
|
|
//transform struct to byte array for sending
|
|
|
-func tweetsToByteArray(tweetsToReturn [][]Tweet) []byte {
|
|
|
+func tweetsToByteArray(tweetsToReturn [][]Tweet, whereFrom int) []byte {
|
|
|
tweetsAsBytes := make([]byte, minimumBlockSize)
|
|
|
- for _, block := range tweetsToReturn {
|
|
|
- var tweetToAppend []byte
|
|
|
+ for blockIndex, block := range tweetsToReturn {
|
|
|
+ var topicPadding []string
|
|
|
+ var blockToAppend []byte
|
|
|
for _, tweet := range block {
|
|
|
- for _, topic := range tweet.Topics {
|
|
|
- tweetToAppend = append(tweetToAppend, []byte(topic)...)
|
|
|
- tweetToAppend = append(tweetToAppend, ","...)
|
|
|
+ for topicIndex, topic := range tweet.Topics {
|
|
|
+ blockToAppend = append(blockToAppend, []byte(topic)...)
|
|
|
+ blockToAppend = append(blockToAppend, ","...)
|
|
|
+
|
|
|
+ //gets the topic used for padding
|
|
|
+ if topicIndex > 0 {
|
|
|
+ topicPadding = append(topicPadding, topic)
|
|
|
+ }
|
|
|
}
|
|
|
//replaces last "," with ";;" bc there is text following and not another topic
|
|
|
- tweetToAppend = tweetToAppend[:len(tweetToAppend)-1]
|
|
|
- tweetToAppend = append(tweetToAppend, []byte(";;")[:]...)
|
|
|
- tweetToAppend = append(tweetToAppend, []byte(tweet.Text)...)
|
|
|
- tweetToAppend = append(tweetToAppend, []byte(";")[0])
|
|
|
+ blockToAppend = blockToAppend[:len(blockToAppend)-1]
|
|
|
+ blockToAppend = append(blockToAppend, []byte(";;")[:]...)
|
|
|
+ blockToAppend = append(blockToAppend, []byte(tweet.Text)...)
|
|
|
+ blockToAppend = append(blockToAppend, []byte(";")[0])
|
|
|
}
|
|
|
+
|
|
|
//adds padding
|
|
|
- tweetToAppend = append(tweetToAppend, []byte(";;")[:]...)
|
|
|
- length := minimumBlockSize - len(tweetToAppend)
|
|
|
- //fmt.Println("len", len(tweetToAppend))
|
|
|
- //todo! replace with grouping
|
|
|
- //grouping using topics from recovered tweets
|
|
|
- if length < 0 {
|
|
|
- fmt.Println("<0", string(tweetToAppend))
|
|
|
+ blockToAppend = append(blockToAppend, []byte(";;")[:]...)
|
|
|
+ remainingLength := minimumBlockSize - len(blockToAppend)
|
|
|
+ //fmt.Println("block", string(blockToAppend))
|
|
|
+
|
|
|
+ //grouping using topic from recovered tweets
|
|
|
+ index := 0
|
|
|
+ for len(topicPadding) > index && remainingLength > 0 && topicPadding[index] != "" {
|
|
|
+ paddingTweet, err := getNextTweet(topicPadding[index], index, whereFrom)
|
|
|
+ if err {
|
|
|
+ break
|
|
|
+ }
|
|
|
+ if remainingLength < len(paddingTweet) {
|
|
|
+ break
|
|
|
+ }
|
|
|
+ blockToAppend = append(blockToAppend, paddingTweet...)
|
|
|
+
|
|
|
+ remainingLength -= len(paddingTweet)
|
|
|
+ index++
|
|
|
}
|
|
|
- padding := bytes.Repeat([]byte(";"), length)
|
|
|
- tweetToAppend = append(tweetToAppend, padding...)
|
|
|
- Xor(tweetToAppend, tweetsAsBytes)
|
|
|
|
|
|
- //fmt.Println(tweetsAsBytes)
|
|
|
+ if blockIndex == 0 {
|
|
|
+ fmt.Println("0000", string(blockToAppend))
|
|
|
+ }
|
|
|
+
|
|
|
+ padding := bytes.Repeat([]byte(";"), remainingLength)
|
|
|
+ blockToAppend = append(blockToAppend, padding...)
|
|
|
+ Xor(blockToAppend, tweetsAsBytes)
|
|
|
|
|
|
+ //fmt.Println(tweetsAsBytes)
|
|
|
}
|
|
|
|
|
|
//fmt.Println("length Returned", len(tweetsAsBytes))
|
|
|
return tweetsAsBytes
|
|
|
}
|
|
|
|
|
|
+//gets the Tweet at index from wantedTopic for padding
|
|
|
+func getNextTweet(wantedTopic string, index, whereFrom int) ([]byte, bool) {
|
|
|
+ tmpdb := dbR
|
|
|
+ if whereFrom == 1 {
|
|
|
+ tmpdb = archive
|
|
|
+ }
|
|
|
+
|
|
|
+ var tweetToReturn Tweet
|
|
|
+ for tweetIndex, tweet := range tmpdb[wantedTopic] {
|
|
|
+ if len(tmpdb[wantedTopic]) <= index {
|
|
|
+ return nil, true
|
|
|
+ } else if tweetIndex < index {
|
|
|
+ continue
|
|
|
+ } else if tweetIndex > index {
|
|
|
+ break
|
|
|
+ }
|
|
|
+
|
|
|
+ //new Tweet
|
|
|
+ if tweet.Text != "" {
|
|
|
+ tweet.RoundPosted = 0
|
|
|
+ tweetToReturn = tweet
|
|
|
+ } else {
|
|
|
+ //"copied" tweet
|
|
|
+ //find tweet with pointers
|
|
|
+ tweet = tmpdb[tweet.TopicPointer][tweet.TextPointer]
|
|
|
+ tweet.RoundPosted = 0
|
|
|
+ tweetToReturn = tweet
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ fmt.Println("nextTweet", tweetToReturn)
|
|
|
+ var tweetToReturnBytes []byte
|
|
|
+ for _, topic := range tweetToReturn.Topics {
|
|
|
+ tweetToReturnBytes = append(tweetToReturnBytes, []byte(topic)...)
|
|
|
+ tweetToReturnBytes = append(tweetToReturnBytes, ","...)
|
|
|
+ }
|
|
|
+ //replaces last "," with ";;" bc there is text following and not another topic
|
|
|
+ tweetToReturnBytes = tweetToReturnBytes[:len(tweetToReturnBytes)-1]
|
|
|
+ tweetToReturnBytes = append(tweetToReturnBytes, []byte(";;")[:]...)
|
|
|
+ tweetToReturnBytes = append(tweetToReturnBytes, []byte(tweetToReturn.Text)...)
|
|
|
+ tweetToReturnBytes = append(tweetToReturnBytes, []byte(";")[0])
|
|
|
+
|
|
|
+ return tweetToReturnBytes, false
|
|
|
+}
|
|
|
+
|
|
|
//see func name
|
|
|
func GetTopicList(whereFrom int) ([]byte, int) {
|
|
|
tmpTopicList := topicList
|