There is another way to find diameter: dynamic programming on the tree. For each node, compute the two deepest subtrees below it. The sum of those two depths is the longest path through that node.
Take the maximum across all nodes. That is your diameter.
This is slower to code than two-BFS, but it generalizes better. If you need to compute diameter while doing other DP on the tree, this fits naturally.