github.com/jlmucb/cloudproxy@v0.0.0-20170830161738-b5aa0b619bc4/go/apps/mixnet/mixnet_directory/mixnet_directory.go (about) 1 // Copyright (c) 2016, Google Inc. All rights reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package main 16 17 import ( 18 "crypto/x509/pkix" 19 "flag" 20 "log" 21 "os" 22 "os/signal" 23 "syscall" 24 "time" 25 26 "github.com/jlmucb/cloudproxy/go/apps/mixnet" 27 "github.com/jlmucb/cloudproxy/go/tao" 28 ) 29 30 var addr = flag.String("addr", "127.0.0.1:9000", "Address and port of this directory.") 31 var network = flag.String("network", "tcp", "Network protocol.") 32 var configPath = flag.String("config", "tao.config", "Path to domain configuration file.") 33 var timeoutDuration = flag.String("timeout", "10s", "Timeout on TCP connections, e.g. \"10s\".") 34 35 // x509 identity of the mixnet router. 36 var x509Identity pkix.Name = pkix.Name{ 37 Organization: []string{"Google Inc."}, 38 OrganizationalUnit: []string{"Cloud Security"}, 39 } 40 41 func serveRouters(dir *mixnet.DirectoryContext) error { 42 for { 43 _, err := dir.Accept() 44 if err != nil { 45 log.Println(err) 46 return err 47 } 48 } 49 } 50 func main() { 51 flag.Parse() 52 timeout, err := time.ParseDuration(*timeoutDuration) 53 if err != nil { 54 log.Fatalf("router: failed to parse timeout duration: %s\n", err) 55 } 56 57 dir, err := mixnet.NewDirectoryContext(*configPath, *network, *addr, 58 timeout, &x509Identity, tao.Parent()) 59 if err != nil { 60 log.Fatalf("failed to configure directory: %s\n", err) 61 } 62 63 sigs := make(chan os.Signal, 1) 64 signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM, syscall.SIGKILL) 65 go func() { 66 sig := <-sigs 67 log.Printf("directory: closing on signal: %s\n", sig) 68 dir.Close() 69 signo := int(sig.(syscall.Signal)) 70 os.Exit(0x80 + signo) 71 }() 72 73 if err := serveRouters(dir); err != nil { 74 log.Fatalf("directory: error while serving: %s\n", err) 75 } 76 }