datatransfer.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 "common/sasl_authenticator.h"
  21. #include "common/async_stream.h"
  22. #include "connection/datanodeconnection.h"
  23. #include <memory>
  24. namespace hdfs {
  25. enum {
  26. kDataTransferVersion = 28,
  27. kDataTransferSasl = 0xdeadbeef,
  28. };
  29. enum Operation {
  30. kWriteBlock = 80,
  31. kReadBlock = 81,
  32. };
  33. template <class Stream> class DataTransferSaslStream : public DataNodeConnection {
  34. public:
  35. DataTransferSaslStream(std::shared_ptr<Stream> stream, const std::string &username,
  36. const std::string &password)
  37. : stream_(stream), authenticator_(username, password) {}
  38. template <class Handler> void Handshake(const Handler &next);
  39. void async_read_some(const MutableBuffer &buf,
  40. std::function<void (const asio::error_code & error,
  41. std::size_t bytes_transferred) > handler) override {
  42. stream_->async_read_some(buf, handler);
  43. }
  44. void async_write_some(const ConstBuffer &buf,
  45. std::function<void (const asio::error_code & error,
  46. std::size_t bytes_transferred) > handler) override {
  47. stream_->async_write_some(buf, handler);
  48. }
  49. void Connect(std::function<void(Status status, std::shared_ptr<DataNodeConnection> dn)> handler) override
  50. {(void)handler; /*TODO: Handshaking goes here*/};
  51. void Cancel();
  52. private:
  53. DataTransferSaslStream(const DataTransferSaslStream &) = delete;
  54. DataTransferSaslStream &operator=(const DataTransferSaslStream &) = delete;
  55. std::shared_ptr<Stream> stream_;
  56. DigestMD5Authenticator authenticator_;
  57. struct ReadSaslMessage;
  58. struct Authenticator;
  59. };
  60. }
  61. #include "datatransfer_impl.h"
  62. #endif