datatransfer.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. #ifndef LIB_READER_DATA_TRANSFER_H_
  19. #define LIB_READER_DATA_TRANSFER_H_
  20. #include "datatransfer.pb.h"
  21. #include "common/sasl_authenticator.h"
  22. #include "common/async_stream.h"
  23. #include "connection/datanodeconnection.h"
  24. #include <memory>
  25. #include <boost/system/error_code.hpp>
  26. namespace hdfs {
  27. enum {
  28. kDataTransferVersion = 28,
  29. kDataTransferSasl = 0xdeadbeef,
  30. };
  31. enum Operation {
  32. kWriteBlock = 80,
  33. kReadBlock = 81,
  34. };
  35. template <class Stream> class DataTransferSaslStream : public DataNodeConnection {
  36. public:
  37. DataTransferSaslStream(std::shared_ptr<Stream> stream, const std::string &username,
  38. const std::string &password)
  39. : stream_(stream), authenticator_(username, password) {}
  40. template <class Handler> void Handshake(const Handler &next);
  41. void async_read_some(const MutableBuffer &buf,
  42. std::function<void (const boost::system::error_code & error,
  43. std::size_t bytes_transferred) > handler) override {
  44. stream_->async_read_some(buf, handler);
  45. }
  46. void async_write_some(const ConstBuffer &buf,
  47. std::function<void (const boost::system::error_code & error,
  48. std::size_t bytes_transferred) > handler) override {
  49. stream_->async_write_some(buf, handler);
  50. }
  51. void Connect(std::function<void(Status status, std::shared_ptr<DataNodeConnection> dn)> handler) override
  52. {(void)handler; /*TODO: Handshaking goes here*/};
  53. void Cancel() override;
  54. private:
  55. DataTransferSaslStream(const DataTransferSaslStream &) = delete;
  56. DataTransferSaslStream &operator=(const DataTransferSaslStream &) = delete;
  57. std::shared_ptr<Stream> stream_;
  58. DigestMD5Authenticator authenticator_;
  59. struct ReadSaslMessage;
  60. struct Authenticator;
  61. };
  62. }
  63. #include "datatransfer_impl.h"
  64. #endif