Skip to content

Commit

Permalink
Extract DNSRecord to its own file
Browse files Browse the repository at this point in the history
  • Loading branch information
bboreham committed Feb 7, 2018
1 parent 9a3b603 commit 1b2e83d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 15 deletions.
39 changes: 39 additions & 0 deletions report/dns.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package report

// DNSRecord contains names that an IP address maps to
type DNSRecord struct {
Forward StringSet `json:"forward,omitempty"`
Reverse StringSet `json:"reverse,omitempty"`
}

// DNSrecords contains all address->name mappings for a report
type DNSRecords map[string]DNSRecord

// Copy makes a copy of the DNSRecords
func (r DNSRecords) Copy() DNSRecords {
cp := make(DNSRecords, len(r))
for k, v := range r {
cp[k] = v
}
return cp
}

// Merge merges the other object into this one, and returns the result object.
// The original is not modified.
func (r DNSRecords) Merge(other DNSRecords) DNSRecords {
if len(other) > len(r) {
r, other = other, r
}
cp := r.Copy()
for k, v := range other {
if v2, ok := cp[k]; ok {
cp[k] = DNSRecord{
Forward: v.Forward.Merge(v2.Forward),
Reverse: v.Reverse.Merge(v2.Reverse),
}
} else {
cp[k] = v
}
}
return cp
}
16 changes: 1 addition & 15 deletions report/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,21 +65,6 @@ var topologyNames = []string{
SwarmService,
}

type DNSRecord struct {
Forward StringSet `json:"forward,omitempty"`
Reverse StringSet `json:"reverse,omitempty"`
}

type DNSRecords map[string]DNSRecord

func (r DNSRecords) Copy() DNSRecords {
cp := make(DNSRecords, len(r))
for k, v := range r {
cp[k] = v
}
return cp
}

// Report is the core data type. It's produced by probes, and consumed and
// stored by apps. It's composed of multiple topologies, each representing
// a different (related, but not equivalent) view of the network.
Expand Down Expand Up @@ -287,6 +272,7 @@ func (r Report) Copy() Report {
// original is not modified.
func (r Report) Merge(other Report) Report {
newReport := r.Copy()
newReport.DNS = newReport.DNS.Merge(other.DNS)
newReport.Sampling = newReport.Sampling.Merge(other.Sampling)
newReport.Window = newReport.Window + other.Window
newReport.Plugins = newReport.Plugins.Merge(other.Plugins)
Expand Down

0 comments on commit 1b2e83d

Please sign in to comment.