{"action":"created","comment":{"url":"https://api.github.com/repos/m-labs/smoltcp/pulls/comments/217934213","pull_request_review_id":155764398,"id":217934213,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIxNzkzNDIxMw==","diff_hunk":"@@ -0,0 +1,425 @@\n+use {Result, Error};\n+use wire::{IpVersion, IpProtocol, IpCidr, IpEndpoint, IpAddress,\n+           Ipv4Cidr, Ipv4Address, Ipv4Packet, Ipv4Repr,\n+           UdpPacket, UdpRepr,\n+           DhcpPacket, DhcpRepr, DhcpMessageType};\n+use wire::dhcpv4::field as dhcpv4_field;\n+use socket::{SocketSet, SocketHandle, RawSocket, RawSocketBuffer};\n+use phy::{Device, ChecksumCapabilities};\n+use iface::EthernetInterface as Interface;\n+use time::{Instant, Duration};\n+use super::{UDP_SERVER_PORT, UDP_CLIENT_PORT};\n+\n+const DISCOVER_TIMEOUT: u64 = 10;\n+const REQUEST_TIMEOUT: u64 = 1;\n+const REQUEST_RETRIES: u16 = 15;\n+const RENEW_INTERVAL: u64 = 60;\n+const RENEW_RETRIES: u16 = 3;\n+const PARAMETER_REQUEST_LIST: &[u8] = &[\n+    dhcpv4_field::OPT_SUBNET_MASK,\n+    dhcpv4_field::OPT_ROUTER,\n+    dhcpv4_field::OPT_DOMAIN_NAME_SERVER,\n+];\n+\n+#[derive(Debug)]\n+struct RequestState {\n+    retry: u16,\n+    server: Ipv4Address,\n+}\n+\n+#[derive(Debug)]\n+struct RenewState {\n+    retry: u16,\n+    server: Ipv4Address,\n+}\n+\n+#[derive(Debug)]\n+enum ClientState {\n+    /// Discovering the DHCP server\n+    Discovering,\n+    /// Requesting an address\n+    Requesting(RequestState),\n+    /// Having an address, refresh it periodically\n+    Renew(RenewState),\n+}\n+\n+pub struct Client {\n+    state: ClientState,\n+    raw_handle: SocketHandle,\n+    /// When to send next request\n+    next_egress: Instant,\n+    transaction_id: u32,\n+    dns_servers: [Option<Ipv4Address>; 3]\n+}\n+\n+/// DHCP client with a RawSocket.\n+///\n+/// To provide memory for the dynamic IP address, configure your\n+/// `Interface` with one of `ip_addrs` and the `ipv4_gateway` being\n+/// `Ipv4Address::UNSPECIFIED`.\n+///\n+/// You must call `poll()` after `iface.poll()` to send and receive\n+/// DHCP packets.\n+impl Client {\n+    /// TODO\n+    pub fn new<'a, 'b, 'c>(sockets: &mut SocketSet<'a, 'b, 'c>, rx_buffer: RawSocketBuffer<'b, 'c>, tx_buffer: RawSocketBuffer<'b, 'c>, now: Instant) -> Self\n+    where 'b: 'c,\n+    {\n+        let raw_socket = RawSocket::new(IpVersion::Ipv4, IpProtocol::Udp, rx_buffer, tx_buffer);\n+        let raw_handle = sockets.add(raw_socket);\n+\n+        Client {\n+            state: ClientState::Discovering,\n+            raw_handle,\n+            next_egress: now,\n+            transaction_id: 1,\n+            dns_servers: [None; 3],\n+        }\n+    }\n+\n+    /// When to send next packet\n+    ///\n+    /// Useful for suspending execution after polling.\n+    pub fn next_poll(&self, now: Instant) -> Duration {\n+        self.next_egress - now\n+    }\n+\n+    /// Process incoming packets on the contained RawSocket, and send\n+    /// DHCP requests when timeouts are ready.\n+    pub fn poll<DeviceT: for<'d> Device<'d>>(&mut self, iface: &mut Interface<DeviceT>, sockets: &mut SocketSet, now: Instant) -> Result<()> {","path":"src/dhcp/clientv4.rs","position":109,"original_position":89,"commit_id":"0bf78eb2ffdd4c9dae367186c7260cc608ed889d","original_commit_id":"0acca35e508b1d9d1f4a78b626853418d30f2245","user":{"login":"astro","id":12923,"node_id":"MDQ6VXNlcjEyOTIz","avatar_url":"https://avatars0.githubusercontent.com/u/12923?v=4","gravatar_id":"","url":"https://api.github.com/users/astro","html_url":"https://github.com/astro","followers_url":"https://api.github.com/users/astro/followers","following_url":"https://api.github.com/users/astro/following{/other_user}","gists_url":"https://api.github.com/users/astro/gists{/gist_id}","starred_url":"https://api.github.com/users/astro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/astro/subscriptions","organizations_url":"https://api.github.com/users/astro/orgs","repos_url":"https://api.github.com/users/astro/repos","events_url":"https://api.github.com/users/astro/events{/privacy}","received_events_url":"https://api.github.com/users/astro/received_events","type":"User","site_admin":false},"body":"any news?","created_at":"2018-09-17T00:32:01Z","updated_at":"2018-09-17T00:32:01Z","html_url":"https://github.com/m-labs/smoltcp/pull/186#discussion_r217934213","pull_request_url":"https://api.github.com/repos/m-labs/smoltcp/pulls/186","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/m-labs/smoltcp/pulls/comments/217934213"},"html":{"href":"https://github.com/m-labs/smoltcp/pull/186#discussion_r217934213"},"pull_request":{"href":"https://api.github.com/repos/m-labs/smoltcp/pulls/186"}},"in_reply_to_id":206568927},"pull_request":{"url":"https://api.github.com/repos/m-labs/smoltcp/pulls/186","id":179802714,"node_id":"MDExOlB1bGxSZXF1ZXN0MTc5ODAyNzE0","html_url":"https://github.com/m-labs/smoltcp/pull/186","diff_url":"https://github.com/m-labs/smoltcp/pull/186.diff","patch_url":"https://github.com/m-labs/smoltcp/pull/186.patch","issue_url":"https://api.github.com/repos/m-labs/smoltcp/issues/186","number":186,"state":"open","locked":false,"title":"DHCPv4 client","user":{"login":"astro","id":12923,"node_id":"MDQ6VXNlcjEyOTIz","avatar_url":"https://avatars0.githubusercontent.com/u/12923?v=4","gravatar_id":"","url":"https://api.github.com/users/astro","html_url":"https://github.com/astro","followers_url":"https://api.github.com/users/astro/followers","following_url":"https://api.github.com/users/astro/following{/other_user}","gists_url":"https://api.github.com/users/astro/gists{/gist_id}","starred_url":"https://api.github.com/users/astro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/astro/subscriptions","organizations_url":"https://api.github.com/users/astro/orgs","repos_url":"https://api.github.com/users/astro/repos","events_url":"https://api.github.com/users/astro/events{/privacy}","received_events_url":"https://api.github.com/users/astro/received_events","type":"User","site_admin":false},"body":"Hi\r\n\r\nThis is an attempt at creating a DHCP client for IPv4. Please give feedback.\r\n\r\nCc: @phil-opp, this PR is uses the work merged in #75.\r\n\r\nI've taken a completely different approach compared to #63. UDP sockets don't allow us to send and receive on unspecified/broadcast IPv4 addresses. Therefore IPv4/UDP is parsed/serialized on top of a `RawSocket`.\r\n\r\n~~There are still two problems with `RawSocketBuffer`:~~\r\n* ~~How do I let the user provide storage? I have tried but failed to accept that as parameters in `Client::new()`.~~ I've found the proper lifetime relation by now.\r\n* ~~The `RawSocket` is getting stuck with `Error::Exhausted` when `contig_window` is too small for the DHCP egress packet. Somehow it appears to behave like sent packets don't get dequeued from the `tx_buffer`. Is that known? What is my code doing wrong regarding RawSocket?~~ See #187\r\n","created_at":"2018-04-05T21:33:12Z","updated_at":"2018-09-17T00:32:01Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ccabc965c41a674f9c901e61b66b7520b1b537dc","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/m-labs/smoltcp/pulls/186/commits","review_comments_url":"https://api.github.com/repos/m-labs/smoltcp/pulls/186/comments","review_comment_url":"https://api.github.com/repos/m-labs/smoltcp/pulls/comments{/number}","comments_url":"https://api.github.com/repos/m-labs/smoltcp/issues/186/comments","statuses_url":"https://api.github.com/repos/m-labs/smoltcp/statuses/0bf78eb2ffdd4c9dae367186c7260cc608ed889d","head":{"label":"astro:dhcp","ref":"dhcp","sha":"0bf78eb2ffdd4c9dae367186c7260cc608ed889d","user":{"login":"astro","id":12923,"node_id":"MDQ6VXNlcjEyOTIz","avatar_url":"https://avatars0.githubusercontent.com/u/12923?v=4","gravatar_id":"","url":"https://api.github.com/users/astro","html_url":"https://github.com/astro","followers_url":"https://api.github.com/users/astro/followers","following_url":"https://api.github.com/users/astro/following{/other_user}","gists_url":"https://api.github.com/users/astro/gists{/gist_id}","starred_url":"https://api.github.com/users/astro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/astro/subscriptions","organizations_url":"https://api.github.com/users/astro/orgs","repos_url":"https://api.github.com/users/astro/repos","events_url":"https://api.github.com/users/astro/events{/privacy}","received_events_url":"https://api.github.com/users/astro/received_events","type":"User","site_admin":false},"repo":{"id":123508171,"node_id":"MDEwOlJlcG9zaXRvcnkxMjM1MDgxNzE=","name":"smoltcp","full_name":"astro/smoltcp","private":false,"owner":{"login":"astro","id":12923,"node_id":"MDQ6VXNlcjEyOTIz","avatar_url":"https://avatars0.githubusercontent.com/u/12923?v=4","gravatar_id":"","url":"https://api.github.com/users/astro","html_url":"https://github.com/astro","followers_url":"https://api.github.com/users/astro/followers","following_url":"https://api.github.com/users/astro/following{/other_user}","gists_url":"https://api.github.com/users/astro/gists{/gist_id}","starred_url":"https://api.github.com/users/astro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/astro/subscriptions","organizations_url":"https://api.github.com/users/astro/orgs","repos_url":"https://api.github.com/users/astro/repos","events_url":"https://api.github.com/users/astro/events{/privacy}","received_events_url":"https://api.github.com/users/astro/received_events","type":"User","site_admin":false},"html_url":"https://github.com/astro/smoltcp","description":"a smol tcp/ip stack","fork":true,"url":"https://api.github.com/repos/astro/smoltcp","forks_url":"https://api.github.com/repos/astro/smoltcp/forks","keys_url":"https://api.github.com/repos/astro/smoltcp/keys{/key_id}","collaborators_url":"https://api.github.com/repos/astro/smoltcp/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/astro/smoltcp/teams","hooks_url":"https://api.github.com/repos/astro/smoltcp/hooks","issue_events_url":"https://api.github.com/repos/astro/smoltcp/issues/events{/number}","events_url":"https://api.github.com/repos/astro/smoltcp/events","assignees_url":"https://api.github.com/repos/astro/smoltcp/assignees{/user}","branches_url":"https://api.github.com/repos/astro/smoltcp/branches{/branch}","tags_url":"https://api.github.com/repos/astro/smoltcp/tags","blobs_url":"https://api.github.com/repos/astro/smoltcp/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/astro/smoltcp/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/astro/smoltcp/git/refs{/sha}","trees_url":"https://api.github.com/repos/astro/smoltcp/git/trees{/sha}","statuses_url":"https://api.github.com/repos/astro/smoltcp/statuses/{sha}","languages_url":"https://api.github.com/repos/astro/smoltcp/languages","stargazers_url":"https://api.github.com/repos/astro/smoltcp/stargazers","contributors_url":"https://api.github.com/repos/astro/smoltcp/contributors","subscribers_url":"https://api.github.com/repos/astro/smoltcp/subscribers","subscription_url":"https://api.github.com/repos/astro/smoltcp/subscription","commits_url":"https://api.github.com/repos/astro/smoltcp/commits{/sha}","git_commits_url":"https://api.github.com/repos/astro/smoltcp/git/commits{/sha}","comments_url":"https://api.github.com/repos/astro/smoltcp/comments{/number}","issue_comment_url":"https://api.github.com/repos/astro/smoltcp/issues/comments{/number}","contents_url":"https://api.github.com/repos/astro/smoltcp/contents/{+path}","compare_url":"https://api.github.com/repos/astro/smoltcp/compare/{base}...{head}","merges_url":"https://api.github.com/repos/astro/smoltcp/merges","archive_url":"https://api.github.com/repos/astro/smoltcp/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/astro/smoltcp/downloads","issues_url":"https://api.github.com/repos/astro/smoltcp/issues{/number}","pulls_url":"https://api.github.com/repos/astro/smoltcp/pulls{/number}","milestones_url":"https://api.github.com/repos/astro/smoltcp/milestones{/number}","notifications_url":"https://api.github.com/repos/astro/smoltcp/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/astro/smoltcp/labels{/name}","releases_url":"https://api.github.com/repos/astro/smoltcp/releases{/id}","deployments_url":"https://api.github.com/repos/astro/smoltcp/deployments","created_at":"2018-03-02T00:19:31Z","updated_at":"2018-08-14T20:36:39Z","pushed_at":"2018-08-22T23:19:21Z","git_url":"git://github.com/astro/smoltcp.git","ssh_url":"git@github.com:astro/smoltcp.git","clone_url":"https://github.com/astro/smoltcp.git","svn_url":"https://github.com/astro/smoltcp","homepage":null,"size":1356,"stargazers_count":0,"watchers_count":0,"language":"Rust","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"other","name":"Other","spdx_id":null,"url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"m-labs:master","ref":"master","sha":"92e970b3798737cfaa2a829d3f1bb7a7353696ee","user":{"login":"m-labs","id":116047,"node_id":"MDEyOk9yZ2FuaXphdGlvbjExNjA0Nw==","avatar_url":"https://avatars3.githubusercontent.com/u/116047?v=4","gravatar_id":"","url":"https://api.github.com/users/m-labs","html_url":"https://github.com/m-labs","followers_url":"https://api.github.com/users/m-labs/followers","following_url":"https://api.github.com/users/m-labs/following{/other_user}","gists_url":"https://api.github.com/users/m-labs/gists{/gist_id}","starred_url":"https://api.github.com/users/m-labs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/m-labs/subscriptions","organizations_url":"https://api.github.com/users/m-labs/orgs","repos_url":"https://api.github.com/users/m-labs/repos","events_url":"https://api.github.com/users/m-labs/events{/privacy}","received_events_url":"https://api.github.com/users/m-labs/received_events","type":"Organization","site_admin":false},"repo":{"id":75406961,"node_id":"MDEwOlJlcG9zaXRvcnk3NTQwNjk2MQ==","name":"smoltcp","full_name":"m-labs/smoltcp","private":false,"owner":{"login":"m-labs","id":116047,"node_id":"MDEyOk9yZ2FuaXphdGlvbjExNjA0Nw==","avatar_url":"https://avatars3.githubusercontent.com/u/116047?v=4","gravatar_id":"","url":"https://api.github.com/users/m-labs","html_url":"https://github.com/m-labs","followers_url":"https://api.github.com/users/m-labs/followers","following_url":"https://api.github.com/users/m-labs/following{/other_user}","gists_url":"https://api.github.com/users/m-labs/gists{/gist_id}","starred_url":"https://api.github.com/users/m-labs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/m-labs/subscriptions","organizations_url":"https://api.github.com/users/m-labs/orgs","repos_url":"https://api.github.com/users/m-labs/repos","events_url":"https://api.github.com/users/m-labs/events{/privacy}","received_events_url":"https://api.github.com/users/m-labs/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/m-labs/smoltcp","description":"a smol tcp/ip stack","fork":false,"url":"https://api.github.com/repos/m-labs/smoltcp","forks_url":"https://api.github.com/repos/m-labs/smoltcp/forks","keys_url":"https://api.github.com/repos/m-labs/smoltcp/keys{/key_id}","collaborators_url":"https://api.github.com/repos/m-labs/smoltcp/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/m-labs/smoltcp/teams","hooks_url":"https://api.github.com/repos/m-labs/smoltcp/hooks","issue_events_url":"https://api.github.com/repos/m-labs/smoltcp/issues/events{/number}","events_url":"https://api.github.com/repos/m-labs/smoltcp/events","assignees_url":"https://api.github.com/repos/m-labs/smoltcp/assignees{/user}","branches_url":"https://api.github.com/repos/m-labs/smoltcp/branches{/branch}","tags_url":"https://api.github.com/repos/m-labs/smoltcp/tags","blobs_url":"https://api.github.com/repos/m-labs/smoltcp/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/m-labs/smoltcp/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/m-labs/smoltcp/git/refs{/sha}","trees_url":"https://api.github.com/repos/m-labs/smoltcp/git/trees{/sha}","statuses_url":"https://api.github.com/repos/m-labs/smoltcp/statuses/{sha}","languages_url":"https://api.github.com/repos/m-labs/smoltcp/languages","stargazers_url":"https://api.github.com/repos/m-labs/smoltcp/stargazers","contributors_url":"https://api.github.com/repos/m-labs/smoltcp/contributors","subscribers_url":"https://api.github.com/repos/m-labs/smoltcp/subscribers","subscription_url":"https://api.github.com/repos/m-labs/smoltcp/subscription","commits_url":"https://api.github.com/repos/m-labs/smoltcp/commits{/sha}","git_commits_url":"https://api.github.com/repos/m-labs/smoltcp/git/commits{/sha}","comments_url":"https://api.github.com/repos/m-labs/smoltcp/comments{/number}","issue_comment_url":"https://api.github.com/repos/m-labs/smoltcp/issues/comments{/number}","contents_url":"https://api.github.com/repos/m-labs/smoltcp/contents/{+path}","compare_url":"https://api.github.com/repos/m-labs/smoltcp/compare/{base}...{head}","merges_url":"https://api.github.com/repos/m-labs/smoltcp/merges","archive_url":"https://api.github.com/repos/m-labs/smoltcp/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/m-labs/smoltcp/downloads","issues_url":"https://api.github.com/repos/m-labs/smoltcp/issues{/number}","pulls_url":"https://api.github.com/repos/m-labs/smoltcp/pulls{/number}","milestones_url":"https://api.github.com/repos/m-labs/smoltcp/milestones{/number}","notifications_url":"https://api.github.com/repos/m-labs/smoltcp/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/m-labs/smoltcp/labels{/name}","releases_url":"https://api.github.com/repos/m-labs/smoltcp/releases{/id}","deployments_url":"https://api.github.com/repos/m-labs/smoltcp/deployments","created_at":"2016-12-02T15:21:02Z","updated_at":"2018-09-16T21:25:08Z","pushed_at":"2018-09-15T20:34:40Z","git_url":"git://github.com/m-labs/smoltcp.git","ssh_url":"git@github.com:m-labs/smoltcp.git","clone_url":"https://github.com/m-labs/smoltcp.git","svn_url":"https://github.com/m-labs/smoltcp","homepage":null,"size":1253,"stargazers_count":579,"watchers_count":579,"language":"Rust","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":49,"mirror_url":null,"archived":false,"open_issues_count":30,"license":{"key":"other","name":"Other","spdx_id":null,"url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":49,"open_issues":30,"watchers":579,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/m-labs/smoltcp/pulls/186"},"html":{"href":"https://github.com/m-labs/smoltcp/pull/186"},"issue":{"href":"https://api.github.com/repos/m-labs/smoltcp/issues/186"},"comments":{"href":"https://api.github.com/repos/m-labs/smoltcp/issues/186/comments"},"review_comments":{"href":"https://api.github.com/repos/m-labs/smoltcp/pulls/186/comments"},"review_comment":{"href":"https://api.github.com/repos/m-labs/smoltcp/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/m-labs/smoltcp/pulls/186/commits"},"statuses":{"href":"https://api.github.com/repos/m-labs/smoltcp/statuses/0bf78eb2ffdd4c9dae367186c7260cc608ed889d"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"astro"}}