lib/protocol, lib/discover, lib/db: Use protocol buffer serialization (fixes #3080)

This changes the BEP protocol to use protocol buffer serialization
instead of XDR, and therefore also the database format. The local
discovery protocol is also updated to be protocol buffer format.

GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3276
LGTM: AudriusButkevicius
This commit is contained in:
Jakob Borg authored and Audrius Butkevicius committed 2016-07-04 10:40:29 +00:00
1 parent 21f5b16e47
commit fa0101bd60
269 files changed
+477296 -4175

No files matched your search

+80
View File
@@ -0,0 +1,80 @@
package main
import (
"bufio"
"flag"
"fmt"
"io"
"log"
"os"
"regexp"
"strings"
"text/tabwriter"
)
func main() {
flag.Parse()
file := flag.Arg(0)
in, err := os.Open(file)
if err != nil {
log.Fatal(err)
}
out, err := os.Create(file + ".tmp")
if err != nil {
log.Fatal(err)
}
if err := formatProto(in, out); err != nil {
log.Fatal(err)
}
if err := os.Rename(file+".tmp", file); err != nil {
log.Fatal(err)
}
}
func formatProto(in io.Reader, out io.Writer) error {
sc := bufio.NewScanner(in)
lineExp := regexp.MustCompile(`([^=]+)\s+([^=\s]+?)\s*=(.+)`)
var tw *tabwriter.Writer
for sc.Scan() {
line := sc.Text()
if strings.HasPrefix(line, "//") {
if _, err := fmt.Fprintln(out, line); err != nil {
return err
}
continue
}
ms := lineExp.FindStringSubmatch(line)
for i := range ms {
ms[i] = strings.TrimSpace(ms[i])
}
if len(ms) == 4 && ms[1] != "option" {
typ := strings.Join(strings.Fields(ms[1]), " ")
name := ms[2]
id := ms[3]
if tw == nil {
tw = tabwriter.NewWriter(out, 4, 4, 1, ' ', 0)
}
if typ == "" {
// We're in an enum
fmt.Fprintf(tw, "\t%s\t= %s\n", name, id)
} else {
// Message
fmt.Fprintf(tw, "\t%s\t%s\t= %s\n", typ, name, id)
}
} else {
if tw != nil {
if err := tw.Flush(); err != nil {
return err
}
tw = nil
}
if _, err := fmt.Fprintln(out, line); err != nil {
return err
}
}
}
return nil
}