Since you are already traversing the tree recursively, you can compute diameter during the traversal. For each node, find the height of its left subtree and the height of its right subtree.
The longest path through this node is left height + right height. Compare this to your current best. The function returns height (for parent's use) while updating the global diameter as a side effect. One traversal, two purposes.