-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
66 lines (53 loc) · 1.79 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"flag"
"fmt"
"log"
"time"
"github.com/google/trillian"
"google.golang.org/grpc"
)
const (
serviceName = "image-transparency-server"
)
var (
tLogEndpoint = flag.String("tlog_endpoint", "", "The gRPC endpoint of the Trillian Log Server.")
tLogID = flag.Int64("tlog_id", 0, "Trillian Log ID")
)
func main() {
flag.Parse()
// Establish gRPC connection w/ Trillian Log Server
log.Printf("[main] Establishing connection w/ Trillian Log Server [%s]", *tLogEndpoint)
conn, err := grpc.Dial(*tLogEndpoint, grpc.WithInsecure())
if err != nil {
log.Fatal(err)
}
defer conn.Close()
// Create a Trillian Log Server client
log.Println("[main] Creating new Trillian Log Client")
tLogClient := trillian.NewTrillianLogClient(conn)
// Eventually this personality will be a server
log.Printf("[main] Creating Server using LogID [%d]", *tLogID)
server := newServer(tLogClient, *tLogID)
// Leaves comprise a primary LeafValue (thing) and may have associated ExtraData(extra)
// The LeafValue will become the hashed value for a node in the Merkle Tree
log.Println("[main] Creating a 'Thing' and something 'Extra'")
thing := newThing(fmt.Sprintf("[%s] Thing", time.Now().Format(time.RFC3339)))
extra := newExtra("Extra")
// Eventually it will be convenient to explicit Request and Response types
resp := &Response{}
// Try to put this Request (Thing+Extra) in the Log
log.Println("[main] Submitting it for inclusion in the Trillian Log")
resp, err = server.put(&Request{
thing: *thing,
extra: *extra,
})
log.Printf("[main] put: %s", resp.status)
// Try to get this Request (Thing+Extra) from the Log
log.Println("[main] Retrieving it from the Trillian Log")
resp, err = server.get(&Request{
thing: *thing,
extra: *extra,
})
log.Printf("[main] get: %s", resp.status)
}