Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

upload client

  • Loading branch information...
commit cc1f78d9e5e74c10423c2cf7d9edc575a47c5a40 1 parent ad6d6ed
bill authored
View
12 src/bdr-proto/test.go
@@ -9,9 +9,11 @@ import (
//import M "math/rand"
import C "crypto/rand"
+const MAX = 4
+
func main() {
req := &bdr_proto.Request{}
- for i := 0; i < 8; i++ {
+ for i := 0; i < MAX; i++ {
// read in 16 bytes from /dev/urandom to sha256
randBytes := make([]byte, 16)
C.Read(randBytes)
@@ -23,12 +25,12 @@ func main() {
sha := sha256.New()
sha.Write(randBytes)
strhash := fmt.Sprintf("%x", sha.Sum(nil))
- fmt.Printf("i=%d sha=%s size=%d\n", i,strhash,size)
-
+ fmt.Printf("i=%d sha=%s size=%d\n", i, strhash, size)
+
req.Blobarray = append(req.Blobarray, &bdr_proto.RequestBlob{Sha256: &strhash, Bsize: &size})
}
- fmt.Printf("%#V %T\n", req, req)
- for i := 0; i < 8; i++ {
+ // fmt.Printf("%#V %T\n", req, req)
+ for i := 0; i < 4; i++ {
fmt.Printf("%s %d \n", *req.Blobarray[i].Sha256, *req.Blobarray[i].Bsize)
}
View
40 src/tlscon/tlscon.go
@@ -0,0 +1,40 @@
+package tlscon
+
+import (
+ "./addservice"
+ "crypto/tls"
+ "crypto/x509"
+ "fmt"
+ "log"
+)
+
+func openTLSClient(ipPort string) (*tls.Conn, error) {
+
+ // Note this loads standard x509 certificates, test keys can be
+ // generated with makecert.sh
+ cert, err := tls.LoadX509KeyPair("certs/client.pem", "certs/client.key")
+ if err != nil {
+ log.Fatalf("server: loadkeys: %s", err)
+ }
+ // InsecureSkipVerify required for unsigned certs with Go1 and later.
+ config := tls.Config{Certificates: []tls.Certificate{cert}, InsecureSkipVerify: true}
+ conn, err := tls.Dial("tcp", ipPort, &config)
+ if err != nil {
+ log.Fatalf("client: dial: %s", err)
+ }
+ log.Println("client: connected to: ", conn.RemoteAddr())
+ // This shows the public key of the server, we will accept any key, but
+ // we could terminate the connection based on the public key if desired.
+ state := conn.ConnectionState()
+ for _, v := range state.PeerCertificates {
+ fmt.Println("Client: Server public key is:")
+ fmt.Println(x509.MarshalPKIXPublicKey(v.PublicKey))
+ }
+ // Lets verify behind the doubt that both ends of the connection
+ // have completed the handshake and negotiated a SSL connection
+ log.Println("client: handshake: ", state.HandshakeComplete)
+ log.Println("client: mutual: ", state.NegotiatedProtocolIsMutual)
+ // All TLS handling has completed, now to pass the connection off to
+ // go-rpcgen/protobuf/AddService
+ return conn, err
+}
View
34 src/upload/upload-client.go
@@ -0,0 +1,34 @@
+package main
+
+import (
+ "fmt"
+ "time"
+)
+
+func server (UpChan chan string,done chan bool) {
+ for f := range UpChan {
+ fmt.Printf("Server: received %s\n",f)
+ }
+ fmt.Print("Server: Channel closed, existing\n")
+}
+
+func client (UpChan chan string, done chan bool) {
+ for i:=0; i<10;i++ {
+ fmt.Print("Client: sending file\n")
+ UpChan <- "/home/bill/test"
+ time.Sleep(400 * time.Millisecond)
+ }
+ fmt.Print("Client: announcing done and existing\n")
+ done <- true
+}
+
+
+func main() {
+ done := make(chan bool)
+ UpChan := make(chan string)
+ go server(UpChan,done)
+ go client(UpChan,done)
+ <- done
+ fmt.Print("Main: Client finished closing server\n")
+ close(UpChan)
+}
Please sign in to comment.
Something went wrong with that request. Please try again.