summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Silverstone <daniel.silverstone@codethink.co.uk>2018-08-10 17:32:16 +0100
committerDaniel Silverstone <daniel.silverstone@codethink.co.uk>2018-08-10 17:32:16 +0100
commit59da21586ead4b62783f3ec347d13d2327964e09 (patch)
treebcfb759ef031b8cecb3cc337ef38b6388f328a8e /src
downloadcache-poker-59da21586ead4b62783f3ec347d13d2327964e09.tar.bz2
Stuff
Diffstat (limited to 'src')
-rw-r--r--src/main.rs97
1 files changed, 97 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs
new file mode 100644
index 0000000..dff2d91
--- /dev/null
+++ b/src/main.rs
@@ -0,0 +1,97 @@
+extern crate bytes;
+extern crate env_logger;
+extern crate futures;
+extern crate http;
+extern crate log;
+extern crate prost;
+extern crate prost_types;
+#[macro_use]
+extern crate prost_derive;
+extern crate tokio_core;
+extern crate tower_grpc;
+extern crate tower_h2;
+extern crate tower_http;
+
+use futures::stream;
+use futures::Future;
+use tokio_core::net::TcpStream;
+use tokio_core::reactor::Core;
+use tower_grpc::Request;
+use tower_h2::client::Connection;
+
+pub mod google {
+ pub mod bytestream {
+ include!(concat!(env!("OUT_DIR"), "/google.bytestream.rs"));
+ }
+ pub mod longrunning {
+ include!(concat!(env!("OUT_DIR"), "/google.longrunning.rs"));
+ }
+ pub mod rpc {
+ include!(concat!(env!("OUT_DIR"), "/google.rpc.rs"));
+ }
+ pub mod protobuf {
+ include!(concat!(env!("OUT_DIR"), "/google.protobuf.rs"));
+ }
+}
+
+pub mod build {
+ pub mod bazel {
+ pub mod remote {
+ pub mod execution {
+ pub mod v2 {
+ include!(concat!(
+ env!("OUT_DIR"),
+ "/build.bazel.remote.execution.v2.rs"
+ ));
+ }
+ }
+ }
+ pub mod semver {
+ include!(concat!(env!("OUT_DIR"), "/build.bazel.semver.rs"));
+ }
+ }
+}
+
+pub fn main() {
+ let _ = ::env_logger::init();
+
+ let mut core = Core::new().unwrap();
+ let reactor = core.handle();
+
+ let addr = "192.168.122.135:1234".parse().unwrap();
+ let uri: http::Uri = format!("http://192.168.122.135:1234").parse().unwrap();
+
+ let upload_blob = TcpStream::connect(&addr, &reactor)
+ .and_then(move |socket| {
+ // Bind the HTTP/2.0 connection
+ Connection::handshake(socket, reactor).map_err(|_| panic!("failed HTTP/2.0 handshake"))
+ })
+ .map(move |conn| {
+ use google::bytestream::client::ByteStream;
+ use tower_http::add_origin;
+ let conn = add_origin::Builder::new().uri(uri).build(conn).unwrap();
+ ByteStream::new(conn)
+ })
+ .and_then(|mut client| {
+ use google::bytestream::WriteRequest;
+ client
+ .write(Request::new(stream::once(Ok(WriteRequest {
+ resource_name:
+ "e12e115acf4552b2568b55e93cbd39394c4ef81c82447fafc997882a02d23677/4"
+ .to_owned(),
+ write_offset: 0,
+ finish_write: true,
+ data: vec![65, 66, 67, 68],
+ }))))
+ .map_err(|e| panic!("gRPC request failed; err={:?}", e))
+ })
+ .and_then(|response| {
+ println!("RESPONSE = {:?}", response);
+ Ok(())
+ })
+ .map_err(|e| {
+ println!("ERR = {:?}", e);
+ });
+
+ core.run(upload_blob).unwrap();
+}